1 #ifndef STAN_MATH_FWD_SCAL_META_OPERANDSANDPARTIALS_HPP
2 #define STAN_MATH_FWD_SCAL_META_OPERANDSANDPARTIALS_HPP
13 template <
typename T_derivative,
16 bool is_vec = is_vector<T>::value,
17 bool is_const = is_constant_struct<T>::value>
18 struct increment_derivative {
19 inline T_derivative operator()(
const T& x,
20 const T_partials& d_dx) {
25 template <
typename T_derivative,
28 struct increment_derivative<T_derivative, T, T_partials, false, false> {
29 inline T_derivative operator()(
const T& x,
30 const T_partials& d_dx) {
31 return d_dx[0] * x.d_;
35 template <
typename T_derivative,
38 struct increment_derivative<T_derivative, T, T_partials, true, false> {
39 inline T_derivative operator()(
const T& x,
40 const T_partials& d_dx) {
42 for (
size_t n = 0; n <
length(x); n++)
49 typename T1,
typename D1,
typename T2,
typename D2,
50 typename T3,
typename D3,
typename T4,
typename D4,
51 typename T5,
typename D5,
typename T6,
typename D6>
52 fvar<T> partials_to_fvar(T& logp,
53 const T1& x1, D1& d_x1,
54 const T2& x2, D2& d_x2,
55 const T3& x3, D3& d_x3,
56 const T4& x4, D4& d_x4,
57 const T5& x5, D5& d_x5,
58 const T6& x6, D6& d_x6) {
60 if (!is_constant_struct<T1>::value)
61 deriv += increment_derivative<T, T1, D1>()(x1, d_x1);
62 if (!is_constant_struct<T2>::value)
63 deriv += increment_derivative<T, T2, D2>()(x2, d_x2);
64 if (!is_constant_struct<T3>::value)
65 deriv += increment_derivative<T, T3, D3>()(x3, d_x3);
66 if (!is_constant_struct<T4>::value)
67 deriv += increment_derivative<T, T4, D4>()(x4, d_x4);
68 if (!is_constant_struct<T5>::value)
69 deriv += increment_derivative<T, T5, D5>()(x5, d_x5);
70 if (!is_constant_struct<T6>::value)
71 deriv += increment_derivative<T, T6, D6>()(x6, d_x6);
72 return fvar<T>(logp, deriv);
98 template<
typename T1,
typename T2,
typename T3,
99 typename T4,
typename T5,
typename T6,
100 typename T_partials_return>
102 fvar<T_partials_return> > {
135 const T4& x4 = 0,
const T5& x5 = 0,
const T6& x6 = 0)
136 : x1_(x1), x2_(x2), x3_(x3), x4_(x4), x5_(x5), x6_(x6),
143 all_partials(new T_partials_return[n_partials]),
165 std::fill(all_partials, all_partials + n_partials, 0);
170 return partials_to_fvar(value,
171 x1_, d_x1, x2_, d_x2,
172 x3_, d_x3, x4_, d_x4,
173 x5_, d_x4, x6_, d_x5);
177 delete[] all_partials;
VectorView< T_partials_return, is_vector< T5 >::value, is_constant_struct< T5 >::value > d_x5
VectorView< T_partials_return, is_vector< T3 >::value, is_constant_struct< T3 >::value > d_x3
T_return_type value(double value)
Returns a T_return_type with the value specified with the partial derivatves.
size_t length(const std::vector< T > &x)
T_return_type value(T_partials_return value)
Metaprogram to determine if a type has a base scalar type that can be assigned to type double...
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)
This class builds partial derivatives with respect to a set of operands.
void derivative(const F &f, const T &x, T &fx, T &dfx_dx)
Return the derivative of the specified univariate function at the specified argument.
VectorView< T_partials_return, is_vector< T1 >::value, is_constant_struct< T1 >::value > d_x1
VectorView< T_partials_return, is_vector< T4 >::value, is_constant_struct< T4 >::value > d_x4
T_partials_return * all_partials
VectorView< T_partials_return, is_vector< T6 >::value, is_constant_struct< T6 >::value > d_x6
void fill(std::vector< T > &x, const S &y)
Fill the specified container with the specified value.
fvar< T_partials_return > T_return_type
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< T_partials_return, is_vector< T2 >::value, is_constant_struct< T2 >::value > d_x2