1 #ifndef STAN__AGRAD__PARTIALS_VARI_HPP
2 #define STAN__AGRAD__PARTIALS_VARI_HPP
19 vari** operands,
double* partials)
23 partials_(partials) { }
25 for (
size_t n = 0; n < N_; ++n)
26 operands_[n]->
adj_ +=
adj_ * partials_[n];
32 T partials_to_var(
double logp,
size_t ,
38 var partials_to_var<var>(
double logp,
size_t nvaris,
39 agrad::vari** all_varis,
40 double* all_partials) {
41 return var(
new agrad::partials_vari(logp, nvaris, all_varis, all_partials));
45 bool is_vec = is_vector<T>::value,
46 bool is_const = is_constant_struct<T>::value>
48 inline size_t set(agrad::vari** ,
const T& ) {
53 struct set_varis <T,true,false>{
54 inline size_t set(agrad::vari** varis,
const T& x) {
55 for (
size_t n = 0; n <
length(x); n++)
61 struct set_varis<agrad::var, false, false> {
62 inline size_t set(agrad::vari** varis,
const agrad::var& x) {
73 template<
typename T1=double,
typename T2=double,
typename T3=double,
74 typename T4=double,
typename T5=double,
typename T6=double,
75 typename T_return_type=
typename return_type<T1,T2,T3,T4,T5,T6>::type>
90 const T4& x4=0,
const T5& x5=0,
const T6& x6=0)
97 all_varis((agrad::
vari**)agrad::
chainable::operator new(sizeof(agrad::
vari*) * nvaris)),
123 base += set_varis<T1>().set(&all_varis[base], x1);
125 base += set_varis<T2>().set(&all_varis[base], x2);
127 base += set_varis<T3>().set(&all_varis[base], x3);
129 base += set_varis<T4>().set(&all_varis[base], x4);
131 base += set_varis<T5>().set(&all_varis[base], x5);
133 set_varis<T6>().set(&all_varis[base], x6);
Metaprogramming struct to detect whether a given type is constant in the mathematical sense (not the ...
T_return_type to_var(double logp)
Abstract base class for variable implementations that handles memory management and applying the chai...
OperandsAndPartials(const T1 &x1=0, const T2 &x2=0, const T3 &x3=0, const T4 &x4=0, const T5 &x5=0, const T6 &x6=0)
A variable implementation that stores operands and derivatives with respect to the variable...
Metaprogram to determine if a type has a base scalar type that can be assigned to type double...
VectorView< double *, is_vector< T2 >::value, is_constant_struct< T2 >::value > d_x2
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
void fill(T &x, const S &y)
Fill the specified container with the specified value.
The variable implementation base class.
VectorView< double *, is_vector< T6 >::value, is_constant_struct< T6 >::value > d_x6
static const bool all_constant
VectorView< double *, is_vector< T4 >::value, is_constant_struct< T4 >::value > d_x4
VectorView< double *, is_vector< T5 >::value, is_constant_struct< T5 >::value > d_x5
VectorView< double *, is_vector< T1 >::value, is_constant_struct< T1 >::value > d_x1
VectorView< double *, is_vector< T3 >::value, is_constant_struct< T3 >::value > d_x3
partials_vari(double value, size_t N, vari **operands, double *partials)
VectorView is a template metaprogram that takes its argument and allows it to be used like a vector...
double adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...