![]() |
Stan Math Library
2.20.0
reverse mode automatic differentiation
|
This template builds partial derivatives with respect to a set of operands. More...
#include <operands_and_partials.hpp>
Public Member Functions | |
operands_and_partials (const Op1 &) | |
operands_and_partials (const Op1 &, const Op2 &) | |
operands_and_partials (const Op1 &, const Op2 &, const Op3 &) | |
operands_and_partials (const Op1 &, const Op2 &, const Op3 &, const Op4 &) | |
operands_and_partials (const Op1 &, const Op2 &, const Op3 &, const Op4 &, const Op5 &) | |
T_return_type | build (double value) |
Build the node to be stored on the autodiff graph. More... | |
Public Attributes | |
internal::ops_partials_edge< double, Op1 > | edge1_ |
internal::ops_partials_edge< double, Op2 > | edge2_ |
internal::ops_partials_edge< double, Op3 > | edge3_ |
internal::ops_partials_edge< double, Op4 > | edge4_ |
internal::ops_partials_edge< double, Op5 > | edge5_ |
This template builds partial derivatives with respect to a set of operands.
There are two reason for the generality of this class. The first is to handle vector and scalar arguments without needing to write additional code. The second is to use this class for writing probability distributions that handle primitives, reverse mode, and forward mode variables seamlessly.
Conceptually, this class is used when we want to manually calculate the derivative of a function and store this manual result on the autodiff stack in a sort of "compressed" form. Think of it like an easy-to-use interface to rev/core/precomputed_gradients.
This class supports nested container ("multivariate") use-cases as well by exposing a partials_vec_ member on edges of the appropriate type.
This base template is instantiated when all operands are primitives and we don't want to calculate derivatives at all. So all Op1 - Op5 must be arithmetic primitives like int or double. This is controlled with the T_return_type type parameter.
Op1 | type of the first operand |
Op2 | type of the second operand |
Op3 | type of the third operand |
Op4 | type of the fourth operand |
Op5 | type of the fifth operand |
T_return_type | return type of the expression. This defaults to calling a template metaprogram that calculates the scalar promotion of Op1..Op4 |
Definition at line 13 of file operands_and_partials.hpp.
|
inlineexplicit |
Definition at line 92 of file operands_and_partials.hpp.
|
inline |
Definition at line 93 of file operands_and_partials.hpp.
|
inline |
Definition at line 94 of file operands_and_partials.hpp.
|
inline |
Definition at line 96 of file operands_and_partials.hpp.
|
inline |
Definition at line 98 of file operands_and_partials.hpp.
|
inline |
Build the node to be stored on the autodiff graph.
This should contain both the value and the tangent.
For scalars (this implementation), we don't calculate any derivatives. For reverse mode, we end up returning a type of var that will calculate the appropriate adjoint using the stored operands and partials. Forward mode just calculates the tangent on the spot and returns it in a vanilla fvar.
value | the return value of the function we are compressing |
Definition at line 115 of file operands_and_partials.hpp.
internal::ops_partials_edge<double, Op1> stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, T_return_type >::edge1_ |
Definition at line 118 of file operands_and_partials.hpp.
internal::ops_partials_edge<double, Op2> stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, T_return_type >::edge2_ |
Definition at line 119 of file operands_and_partials.hpp.
internal::ops_partials_edge<double, Op3> stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, T_return_type >::edge3_ |
Definition at line 120 of file operands_and_partials.hpp.
internal::ops_partials_edge<double, Op4> stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, T_return_type >::edge4_ |
Definition at line 121 of file operands_and_partials.hpp.
internal::ops_partials_edge<double, Op5> stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, T_return_type >::edge5_ |
Definition at line 122 of file operands_and_partials.hpp.