Automatic Differentiation
 
Loading...
Searching...
No Matches
fill.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_FILL_HPP
2#define STAN_MATH_REV_FUN_FILL_HPP
3
7#include <vector>
8
9namespace stan {
10namespace math {
11
23template <typename VarMat, typename S, require_var_matrix_t<VarMat>* = nullptr,
24 require_var_t<S>* = nullptr>
25inline void fill(VarMat& x, const S& y) {
26 arena_t<plain_type_t<value_type_t<VarMat>>> prev_vals(x.val().eval());
27 x.vi_->val_.fill(y.val());
28 reverse_pass_callback([x, y, prev_vals]() mutable {
29 x.vi_->val_ = prev_vals;
30 y.adj() += x.adj().sum();
31 x.adj().setZero();
32 });
33}
34
46template <typename VarMat, typename S, require_var_matrix_t<VarMat>* = nullptr,
47 require_arithmetic_t<S>* = nullptr>
48inline void fill(VarMat& x, const S& y) {
49 arena_t<plain_type_t<value_type_t<VarMat>>> prev_vals(x.val().eval());
50 x.vi_->val_.fill(y);
51 reverse_pass_callback([x, prev_vals]() mutable {
52 x.vi_->val_ = prev_vals;
53 x.adj().setZero();
54 });
55}
56
57} // namespace math
58} // namespace stan
59
60#endif
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
void fill(EigMat &x, const S &y)
Fill the specified container with the specified value.
Definition fill.hpp:24
typename internal::arena_type_impl< std::decay_t< T > >::type arena_t
Determines a type that can be used in place of T that does any dynamic allocations on the AD stack.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...