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 nvaris,
34 double* all_partials) {
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));
48 inline size_t set(agrad::vari** varis,
const T& x) {
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,
90 const T4& x4=0,
const T5& x5=0,
const T6& x6=0)
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);
Abstract base class for variable implementations that handles memory management and applying the chai...
void chain()
Apply the chain rule to this variable based on the variables on which it depends.
partials_vari(double value, size_t N, vari **operands, double *partials)
The variable implementation base class.
double adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...
Probability, optimization and sampling library.
size_t length(const T &x)
A variable implementation that stores operands and derivatives with respect to the variable.
VectorView< double *, is_vector< T5 >::value > d_x5
VectorView< double *, is_vector< T1 >::value > d_x1
VectorView< double *, is_vector< T2 >::value > d_x2
T_return_type to_var(double logp)
VectorView< double *, is_vector< T3 >::value > d_x3
VectorView< double *, is_vector< T6 >::value > d_x6
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)
VectorView< double *, is_vector< T4 >::value > d_x4
static const bool all_constant
Metaprogram to determine if a type has a base scalar type that can be assigned to type double.
Metaprogramming struct to detect whether a given type is constant in the mathematical sense (not the ...
boost::math::tools::promote_args< typename scalar_type< T1 >::type, typename scalar_type< T2 >::type, typename scalar_type< T3 >::type, typename scalar_type< T4 >::type, typename scalar_type< T5 >::type, typename scalar_type< T6 >::type >::type type