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
8#include <vector>
9
10namespace stan {
11namespace math {
12
24template <typename VarMat, typename S, require_var_matrix_t<VarMat>* = nullptr,
25 require_var_t<S>* = nullptr>
26inline void fill(VarMat& x, const S& y) {
27 arena_t<plain_type_t<value_type_t<VarMat>>> prev_vals(x.val().eval());
28 x.vi_->val_.fill(y.val());
29 reverse_pass_callback([x, y, prev_vals]() mutable {
30 x.vi_->val_ = prev_vals;
31 y.adj() += x.adj().sum();
32 x.adj().setZero();
33 });
34}
35
47template <typename VarMat, typename S, require_var_matrix_t<VarMat>* = nullptr,
48 require_arithmetic_t<S>* = nullptr>
49inline void fill(VarMat& x, const S& y) {
50 arena_t<plain_type_t<value_type_t<VarMat>>> prev_vals(x.val().eval());
51 x.vi_->val_.fill(y);
52 reverse_pass_callback([x, prev_vals]() mutable {
53 x.vi_->val_ = prev_vals;
54 x.adj().setZero();
55 });
56}
57
58} // namespace math
59} // namespace stan
60
61#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 ...