Automatic Differentiation
 
Loading...
Searching...
No Matches
to_var_value.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_TO_VAR_VALUE_HPP
2#define STAN_MATH_REV_FUN_TO_VAR_VALUE_HPP
3
8
9namespace stan {
10namespace math {
11
20template <typename T, require_eigen_vt<is_var, T>* = nullptr>
21inline var_value<
22 Eigen::Matrix<double, T::RowsAtCompileTime, T::ColsAtCompileTime>>
23to_var_value(const T& a) {
25 var_value<promote_scalar_t<double, T>> res(a_arena.val());
27 [res, a_arena]() mutable { a_arena.adj() += res.adj(); });
28 return res;
29}
30
37template <typename T, require_var_t<T>* = nullptr>
38inline T to_var_value(T&& a) {
39 return std::forward<T>(a);
40}
41
49template <typename T>
50inline auto to_var_value(const std::vector<T>& a) {
51 std::vector<decltype(to_var_value(std::declval<T>()))> out;
52 out.reserve(a.size());
53 for (size_t i = 0; i < a.size(); ++i) {
54 out.emplace_back(to_var_value(a[i]));
55 }
56 return out;
57}
58
59} // namespace math
60} // namespace stan
61
62#endif
Equivalent to Eigen::Matrix, except that the data is stored on AD stack.
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
var_value< Eigen::Matrix< double, T::RowsAtCompileTime, T::ColsAtCompileTime > > to_var_value(const T &a)
Converts an Eigen matrix (or vector or row_vector) or expression of vars into var_value.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...