1#ifndef STAN_MATH_FWD_META_OPERANDS_AND_PARTIALS_HPP
2#define STAN_MATH_FWD_META_OPERANDS_AND_PARTIALS_HPP
25static constexpr auto sum_dx() {
return static_cast<double>(0.0); }
46template <
typename T1,
typename T2,
typename... Types>
47inline auto sum_dx(T1& a, T2& b, Types&... args) {
48 return a.dx() + b.dx() +
sum_dx(args...);
51template <
typename InnerType,
typename T>
54 using Op = std::decay_t<T>;
55 using Dx = std::decay_t<InnerType>;
60 : partial_(0), partials_(partial_), operands_(op) {}
64 : partial_(other.partial_),
66 operands_(other.operands_) {}
70 : partial_(other.partial_),
72 operands_(other.operands_) {}
76 inline Dx dx() {
return this->partial_ * this->operands_.d_; }
80template <
typename InnerType,
typename T>
83 using Op = std::decay_t<T>;
84 using Dx = std::decay_t<InnerType>;
94 : partials_(other.partials_),
95 partials_vec_(partials_),
96 operands_(other.operands_) {}
101 : partials_(
std::move(other.partials_)),
102 partials_vec_(partials_),
103 operands_(other.operands_) {}
112template <
typename Dx,
typename ViewElt>
119 template <
typename OpT, require_eigen_vt<is_fvar, OpT>* =
nullptr>
126 : partials_(other.partials_),
127 partials_vec_(partials_),
128 operands_(other.operands_) {}
133 : partials_(
std::move(other.partials_)),
134 partials_vec_(partials_),
135 operands_(other.operands_) {}
145template <
typename Dx,
int R,
int C>
148 using Op = std::vector<Eigen::Matrix<fvar<Dx>, R, C>>;
152 : partials_vec_(ops.
size()), operands_(ops) {
153 for (
size_t i = 0; i < ops.size(); ++i) {
154 partials_vec_[i] = partial_t::Zero(ops[i].
rows(), ops[i].
cols());
162 for (
size_t i = 0; i < this->operands_.size(); ++i) {
170template <
typename Dx>
173 using Op = std::vector<std::vector<fvar<Dx>>>;
177 : partials_vec_(
stan::math::
size(ops)), operands_(ops) {
186 for (
size_t i = 0; i < this->operands_.size(); ++i) {
187 for (
size_t j = 0; j < this->operands_[i].size(); ++j) {
188 derivative += this->partials_vec_[i][j] * this->operands_[i][j].d_;
236template <
typename Op1,
typename Op2,
typename Op3,
typename Op4,
typename Op5,
237 typename Op6,
typename Op7,
typename Op8,
typename Dx>
258 const Op4& o4,
const Op5& o5)
261 const Op4& o4,
const Op5& o5,
const Op6& o6)
269 const Op4& o4,
const Op5& o5,
const Op6& o6,
279 const Op4& o4,
const Op5& o5,
const Op6& o6,
280 const Op7& o7,
const Op8& o8)
promote_scalar_t< Dx, ViewElt > partials_t
ops_partials_edge(const OpT &ops)
ops_partials_edge(ops_partials_edge< Dx, ViewElt, require_eigen_vt< is_fvar, ViewElt > > &&other)
ops_partials_edge(const ops_partials_edge< Dx, ViewElt, require_eigen_vt< is_fvar, ViewElt > > &other)
plain_type_t< ViewElt > Op
std::vector< partial_t > partials_vec_
std::vector< Eigen::Matrix< fvar< Dx >, R, C > > Op
ops_partials_edge(const Op &ops)
Eigen::Matrix< Dx, R, C > partial_t
ops_partials_edge(const Op &ops)
std::vector< Dx > partial_t
std::vector< std::vector< fvar< Dx > > > Op
std::vector< partial_t > partials_vec_
ops_partials_edge(ops_partials_edge< InnerType, T, require_fvar_t< T > > &&other)
ops_partials_edge(const ops_partials_edge< InnerType, T, require_fvar_t< T > > &other)
std::decay_t< InnerType > Dx
ops_partials_edge(const T &op)
ops_partials_edge(ops_partials_edge< InnerType, T, require_std_vector_vt< is_fvar, T > > &&other)
ops_partials_edge(const Op &ops)
std::decay_t< InnerType > Dx
ops_partials_edge(const ops_partials_edge< InnerType, T, require_std_vector_vt< is_fvar, T > > &other)
Eigen::Matrix< Dx, -1, 1 > partials_t
An edge holds both the operands and its associated partial derivatives.
operands_and_partials(const Op1 &o1)
operands_and_partials(const Op1 &o1, const Op2 &o2, const Op3 &o3)
operands_and_partials(const Op1 &o1, const Op2 &o2, const Op3 &o3, const Op4 &o4, const Op5 &o5, const Op6 &o6)
operands_and_partials(const Op1 &o1, const Op2 &o2, const Op3 &o3, const Op4 &o4, const Op5 &o5, const Op6 &o6, const Op7 &o7, const Op8 &o8)
internal::ops_partials_edge< Dx, std::decay_t< Op4 > > edge4_
internal::ops_partials_edge< Dx, std::decay_t< Op3 > > edge3_
internal::ops_partials_edge< Dx, std::decay_t< Op6 > > edge6_
internal::ops_partials_edge< Dx, std::decay_t< Op7 > > edge7_
internal::ops_partials_edge< Dx, std::decay_t< Op5 > > edge5_
operands_and_partials(const Op1 &o1, const Op2 &o2, const Op3 &o3, const Op4 &o4, const Op5 &o5, const Op6 &o6, const Op7 &o7)
internal::ops_partials_edge< Dx, std::decay_t< Op8 > > edge8_
operands_and_partials(const Op1 &o1, const Op2 &o2, const Op3 &o3, const Op4 &o4)
operands_and_partials(const Op1 &o1, const Op2 &o2, const Op3 &o3, const Op4 &o4, const Op5 &o5)
internal::ops_partials_edge< Dx, std::decay_t< Op2 > > edge2_
operands_and_partials(const Op1 &o1, const Op2 &o2)
internal::ops_partials_edge< Dx, std::decay_t< Op1 > > edge1_
internal::ops_partials_edge< double, std::decay_t< Op2 > > edge2_
internal::ops_partials_edge< double, std::decay_t< Op7 > > edge7_
internal::ops_partials_edge< double, std::decay_t< Op4 > > edge4_
internal::ops_partials_edge< double, std::decay_t< Op6 > > edge6_
internal::ops_partials_edge< double, std::decay_t< Op1 > > edge1_
internal::ops_partials_edge< double, std::decay_t< Op8 > > edge8_
internal::ops_partials_edge< double, std::decay_t< Op5 > > edge5_
internal::ops_partials_edge< double, std::decay_t< Op3 > > edge3_
This template builds partial derivatives with respect to a set of operands.
require_t< container_type_check_base< is_eigen, value_type_t, TypeCheck, Check... > > require_eigen_vt
Require type satisfies is_eigen.
require_t< is_fvar< std::decay_t< T > > > require_fvar_t
Require type satisfies is_fvar.
elt_multiply_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > elt_multiply(T_a &&a, T_b &&b)
auto as_column_vector_or_scalar(T &&a)
as_column_vector_or_scalar of a kernel generator expression.
int64_t cols(const T_x &x)
Returns the number of columns in the specified kernel generator expression.
int64_t rows(const T_x &x)
Returns the number of rows in the specified kernel generator expression.
require_t< container_type_check_base< is_std_vector, value_type_t, TypeCheck, Check... > > require_std_vector_vt
Require type satisfies is_std_vector.
T_return_type build(Dx value)
Build the node to be stored on the autodiff graph.
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
static constexpr auto sum_dx()
End of recursion for summing .dx() for fvar<T> ops and partials.
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.
typename promote_scalar_type< std::decay_t< T >, std::decay_t< S > >::type promote_scalar_t
T eval(T &&arg)
Inputs which have a plain_type equal to the own time are forwarded unmodified (for Eigen expressions ...
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
auto dot_product(const T_a &a, const T_b &b)
Returns the dot product of the specified vectors.
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Defines a static member function type which is defined to be false as the primitive scalar types cann...
This template class represents scalars used in forward-mode automatic differentiation,...