Automatic Differentiation
 
Loading...
Searching...
No Matches
save_varis.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_CORE_SAVE_VARIS_HPP
2#define STAN_MATH_REV_CORE_SAVE_VARIS_HPP
3
8
9#include <utility>
10#include <vector>
11
12namespace stan {
13namespace math {
14
15template <typename... Pargs>
16inline vari** save_varis(vari** dest, const var& x, Pargs&&... args);
17
18template <typename VarVec, require_std_vector_vt<is_var, VarVec>* = nullptr,
19 typename... Pargs>
20inline vari** save_varis(vari** dest, VarVec&& x, Pargs&&... args);
21
22template <typename VecContainer,
23 require_std_vector_st<is_var, VecContainer>* = nullptr,
24 require_std_vector_vt<is_container, VecContainer>* = nullptr,
25 typename... Pargs>
26inline vari** save_varis(vari** dest, VecContainer&& x, Pargs&&... args);
27
28template <typename EigT, require_eigen_vt<is_var, EigT>* = nullptr,
29 typename... Pargs>
30inline vari** save_varis(vari** dest, EigT&& x, Pargs&&... args);
31
32template <typename Arith, require_st_arithmetic<Arith>* = nullptr,
33 typename... Pargs>
34inline vari** save_varis(vari** dest, Arith&& x, Pargs&&... args);
35
36inline vari** save_varis(vari** dest);
37
50template <typename... Pargs>
51inline vari** save_varis(vari** dest, const var& x, Pargs&&... args) {
52 *dest = x.vi_;
53 return save_varis(dest + 1, std::forward<Pargs>(args)...);
54}
55
69template <typename VarVec, require_std_vector_vt<is_var, VarVec>*,
70 typename... Pargs>
71inline vari** save_varis(vari** dest, VarVec&& x, Pargs&&... args) {
72 for (int i = 0; i < x.size(); ++i) {
73 dest[i] = x[i].vi_;
74 }
75 return save_varis(dest + x.size(), std::forward<Pargs>(args)...);
76}
77
91template <typename VecContainer, require_std_vector_st<is_var, VecContainer>*,
92 require_std_vector_vt<is_container, VecContainer>*, typename... Pargs>
93inline vari** save_varis(vari** dest, VecContainer&& x, Pargs&&... args) {
94 for (size_t i = 0; i < x.size(); ++i) {
95 dest = save_varis(dest, x[i]);
96 }
97 return save_varis(dest, std::forward<Pargs>(args)...);
98}
99
113template <typename EigT, require_eigen_vt<is_var, EigT>*, typename... Pargs>
114inline vari** save_varis(vari** dest, EigT&& x, Pargs&&... args) {
115 for (int i = 0; i < x.size(); ++i) {
116 dest[i] = x.coeff(i).vi_;
117 }
118 return save_varis(dest + x.size(), std::forward<Pargs>(args)...);
119}
120
134template <typename Arith, require_st_arithmetic<Arith>*, typename... Pargs>
135inline vari** save_varis(vari** dest, Arith&& x, Pargs&&... args) {
136 return save_varis(dest, std::forward<Pargs>(args)...);
137}
138
144inline vari** save_varis(vari** dest) { return dest; }
145
146} // namespace math
147} // namespace stan
148
149#endif
vari_value< double > vari
Definition vari.hpp:197
vari ** save_varis(vari **dest, const var &x, Pargs &&... args)
Save the vari pointer in x into the memory pointed to by dest, increment the dest storage pointer,...
var_value< double > var
Definition var.hpp:1187
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...