Stan Math Library  2.20.0
reverse mode automatic differentiation
operands_and_partials.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_SCAL_META_OPERANDS_AND_PARTIALS_HPP
2 #define STAN_MATH_FWD_SCAL_META_OPERANDS_AND_PARTIALS_HPP
3 
7 
8 namespace stan {
9 namespace math {
10 namespace internal {
11 template <typename Dx>
12 class ops_partials_edge<Dx, fvar<Dx> > {
13  public:
14  typedef fvar<Dx> Op;
17  explicit ops_partials_edge(const Op& op)
18  : partial_(0), partials_(partial_), operand_(op) {}
19 
20  private:
21  template <typename, typename, typename, typename, typename, typename>
23  const Op& operand_;
24 
25  Dx dx() { return this->partials_[0] * this->operand_.d_; }
26 };
27 } // namespace internal
28 
65 template <typename Op1, typename Op2, typename Op3, typename Op4, typename Op5,
66  typename Dx>
67 class operands_and_partials<Op1, Op2, Op3, Op4, Op5, fvar<Dx> > {
68  public:
75  explicit operands_and_partials(const Op1& o1) : edge1_(o1) {}
76  operands_and_partials(const Op1& o1, const Op2& o2)
77  : edge1_(o1), edge2_(o2) {}
78  operands_and_partials(const Op1& o1, const Op2& o2, const Op3& o3)
79  : edge1_(o1), edge2_(o2), edge3_(o3) {}
80  operands_and_partials(const Op1& o1, const Op2& o2, const Op3& o3,
81  const Op4& o4)
82  : edge1_(o1), edge2_(o2), edge3_(o3), edge4_(o4) {}
83  operands_and_partials(const Op1& o1, const Op2& o2, const Op3& o3,
84  const Op4& o4, const Op5& o5)
85  : edge1_(o1), edge2_(o2), edge3_(o3), edge4_(o4), edge5_(o5) {}
86 
100  T_return_type build(Dx value) {
101  Dx deriv
102  = edge1_.dx() + edge2_.dx() + edge3_.dx() + edge4_.dx() + edge5_.dx();
103  return T_return_type(value, deriv);
104  }
105 };
106 } // namespace math
107 } // namespace stan
108 #endif
T d_
The tangent (derivative) of this variable.
Definition: fvar.hpp:50
An edge holds both the operands and its associated partial derivatives.
This template builds partial derivatives with respect to a set of operands.
operands_and_partials(const Op1 &o1, const Op2 &o2, const Op3 &o3, const Op4 &o4)
T_return_type build(Dx value)
Build the node to be stored on the autodiff graph.
operands_and_partials(const Op1 &o1, const Op2 &o2, const Op3 &o3, const Op4 &o4, const Op5 &o5)
This template class represents scalars used in forward-mode automatic differentiation, which consist of values and directional derivatives of the specified template type.
Definition: fvar.hpp:41

     [ Stan Home Page ] © 2011–2018, Stan Development Team.