1 #ifndef STAN_MATH_REV_SCAL_META_OPERANDSANDPARTIALS_HPP
2 #define STAN_MATH_REV_SCAL_META_OPERANDSANDPARTIALS_HPP
14 class partials_vari :
public vari {
20 partials_vari(
double value,
22 vari** operands,
double* partials)
26 partials_(partials) { }
28 for (
size_t n = 0; n <
N_; ++n)
29 operands_[n]->adj_ += adj_ * partials_[n];
33 var partials_to_var(
double logp,
size_t nvaris,
35 double* all_partials) {
36 return var(
new partials_vari(logp, nvaris, all_varis,
41 bool is_vec = is_vector<T>::value,
42 bool is_const = is_constant_struct<T>::value>
44 inline size_t set(vari** ,
const T& ) {
49 struct set_varis<T, true, false> {
50 inline size_t set(vari** varis,
const T& x) {
51 for (
size_t n = 0; n <
length(x); n++)
57 struct set_varis<var, false, false> {
58 inline size_t set(vari** varis,
const var& x) {
87 template<
typename T1,
typename T2,
typename T3,
88 typename T4,
typename T5,
typename T6>
124 const T4& x4 = 0,
const T5& x5 = 0,
const T6& x6 = 0)
132 all_varis(static_cast<
vari**>
134 (sizeof(
vari*) * nvaris))),
135 all_partials(static_cast<double*>
137 (sizeof(double) * nvaris))),
161 base += set_varis<T1>().set(&all_varis[base], x1);
163 base += set_varis<T2>().set(&all_varis[base], x2);
165 base += set_varis<T3>().set(&all_varis[base], x3);
167 base += set_varis<T4>().set(&all_varis[base], x4);
169 base += set_varis<T5>().set(&all_varis[base], x5);
171 set_varis<T6>().set(&all_varis[base], x6);
172 std::fill(all_partials, all_partials+nvaris, 0);
184 return partials_to_var(value, nvaris, all_varis,
T_return_type value(double value)
Returns a T_return_type with the value specified with the partial derivatves.
VectorView< double, is_vector< T4 >::value, is_constant_struct< T4 >::value > d_x4
The variable implementation base class.
size_t length(const std::vector< T > &x)
stan::math::var value(double value)
Returns a T_return_type with the value specified with the partial derivatves.
Independent (input) and dependent (output) variables for gradients.
Metaprogram to determine if a type has a base scalar type that can be assigned to type double...
VectorView< double, is_vector< T1 >::value, is_constant_struct< T1 >::value > d_x1
This class builds partial derivatives with respect to a set of operands.
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)
Constructor.
VectorView< double, is_vector< T5 >::value, is_constant_struct< T5 >::value > d_x5
VectorView< double, is_vector< T2 >::value, is_constant_struct< T2 >::value > d_x2
void fill(std::vector< T > &x, const S &y)
Fill the specified container with the specified value.
VectorView< double, is_vector< T3 >::value, is_constant_struct< T3 >::value > d_x3
VectorView is a template expression that is constructed with a container or scalar, which it then allows to be used as an array using operator[].
VectorView< double, is_vector< T6 >::value, is_constant_struct< T6 >::value > d_x6