Automatic Differentiation
 
Loading...
Searching...
No Matches
from_var_value.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_FROM_VAR_VALUE_HPP
2#define STAN_MATH_REV_FUN_FROM_VAR_VALUE_HPP
3
8
9namespace stan {
10namespace math {
11
19template <typename T, require_var_matrix_t<T>* = nullptr>
20Eigen::Matrix<var, T::RowsAtCompileTime, T::ColsAtCompileTime> from_var_value(
21 const T& a) {
23 res(a.val());
24 reverse_pass_callback([res, a]() mutable { a.vi_->adj_ += res.adj(); });
25 return res;
26}
27
34template <
35 typename T,
37 conjunction<is_eigen<T>, is_var<scalar_type_t<T>>>,
38 std::is_same<std::decay_t<T>, var>,
41 return std::forward<T>(a);
42}
43
51template <typename T>
52auto from_var_value(const std::vector<T>& a) {
53 std::vector<decltype(from_var_value(std::declval<T>()))> out;
54 out.reserve(a.size());
55 for (size_t i = 0; i < a.size(); ++i) {
56 out.emplace_back(from_var_value(a[i]));
57 }
58 return out;
59}
60
61} // namespace math
62} // namespace stan
63
64#endif
Equivalent to Eigen::Matrix, except that the data is stored on AD stack.
std::integral_constant< bool, B > bool_constant
Alias for structs used for wraps a static constant of bool.
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
Eigen::Matrix< var, T::RowsAtCompileTime, T::ColsAtCompileTime > from_var_value(const T &a)
Converts var_value into an Eigen Matrix.
var_value< double > var
Definition var.hpp:1187
std::enable_if_t< math::disjunction< Checks... >::value > require_any_t
If any condition is true, template is enabled.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Defines a static member named value which is defined to be false as the primitive scalar types cannot...
Definition is_var.hpp:14