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);
Metaprogramming struct to detect whether a given type is constant in the mathematical sense (not the ...
VectorView< double *, is_vector< T2 >::value > d_x2
Probability, optimization and sampling library.
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)
VectorView< double *, is_vector< T3 >::value > d_x3
A variable implementation that stores operands and derivatives with respect to the variable...
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
Metaprogram to determine if a type has a base scalar type that can be assigned to type double...
VectorView< double *, is_vector< T6 >::value > d_x6
VectorView< double *, is_vector< T1 >::value > d_x1
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
VectorView< double *, is_vector< T4 >::value > d_x4
The variable implementation base class.
VectorView< double *, is_vector< T5 >::value > d_x5
static const bool all_constant
size_t length(const T &x)
partials_vari(double value, size_t N, vari **operands, double *partials)
double adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...