Stan Math Library  2.20.0
reverse mode automatic differentiation
Public Types | Public Member Functions | Public Attributes | List of all members
stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, fvar< Dx > > Class Template Reference

This class builds partial derivatives with respect to a set of operands. More...

#include <operands_and_partials.hpp>

Public Types

typedef fvar< Dx > T_return_type
 

Public Member Functions

 operands_and_partials (const Op1 &o1)
 
 operands_and_partials (const Op1 &o1, const Op2 &o2)
 
 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)
 
 operands_and_partials (const Op1 &o1, const Op2 &o2, const Op3 &o3, const Op4 &o4, const Op5 &o5)
 
T_return_type build (Dx value)
 Build the node to be stored on the autodiff graph. More...
 

Public Attributes

internal::ops_partials_edge< Dx, Op1 > edge1_
 
internal::ops_partials_edge< Dx, Op2 > edge2_
 
internal::ops_partials_edge< Dx, Op3 > edge3_
 
internal::ops_partials_edge< Dx, Op4 > edge4_
 
internal::ops_partials_edge< Dx, Op5 > edge5_
 

Detailed Description

template<typename Op1, typename Op2, typename Op3, typename Op4, typename Op5, typename Dx>
class stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, fvar< Dx > >

This class 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 now supports multivariate use-cases as well by exposing edge::_.partials_vec

This is the specialization for when the return type is fvar, which should be for forward mode and all higher-order cases.

NB: since ops_partials_edge.partials_ and ops_partials_edge.partials_vec are sometimes represented internally as a broadcast_array, we need to take care with assignments to them. Indeed, we can assign any right hand side which allows for indexing to a broadcast_array. The resulting behaviour is that the entry for the first index is what gets assigned. The most common use-case should be where the rhs is some container of length 1.

Template Parameters
Op1type of the first operand
Op2type of the second operand
Op3type of the third operand
Op4type of the fourth operand
Op5type of the fifth operand
T_return_typereturn type of the expression. This defaults to a template metaprogram that calculates the scalar promotion of Op1 – Op5

Definition at line 67 of file operands_and_partials.hpp.

Member Typedef Documentation

◆ T_return_type

template<typename Op1 , typename Op2 , typename Op3 , typename Op4 , typename Op5 , typename Dx >
typedef fvar<Dx> stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, fvar< Dx > >::T_return_type

Definition at line 74 of file operands_and_partials.hpp.

Constructor & Destructor Documentation

◆ operands_and_partials() [1/5]

template<typename Op1 , typename Op2 , typename Op3 , typename Op4 , typename Op5 , typename Dx >
stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, fvar< Dx > >::operands_and_partials ( const Op1 &  o1)
inlineexplicit

Definition at line 75 of file operands_and_partials.hpp.

◆ operands_and_partials() [2/5]

template<typename Op1 , typename Op2 , typename Op3 , typename Op4 , typename Op5 , typename Dx >
stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, fvar< Dx > >::operands_and_partials ( const Op1 &  o1,
const Op2 &  o2 
)
inline

Definition at line 76 of file operands_and_partials.hpp.

◆ operands_and_partials() [3/5]

template<typename Op1 , typename Op2 , typename Op3 , typename Op4 , typename Op5 , typename Dx >
stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, fvar< Dx > >::operands_and_partials ( const Op1 &  o1,
const Op2 &  o2,
const Op3 &  o3 
)
inline

Definition at line 78 of file operands_and_partials.hpp.

◆ operands_and_partials() [4/5]

template<typename Op1 , typename Op2 , typename Op3 , typename Op4 , typename Op5 , typename Dx >
stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, fvar< Dx > >::operands_and_partials ( const Op1 &  o1,
const Op2 &  o2,
const Op3 &  o3,
const Op4 &  o4 
)
inline

Definition at line 80 of file operands_and_partials.hpp.

◆ operands_and_partials() [5/5]

template<typename Op1 , typename Op2 , typename Op3 , typename Op4 , typename Op5 , typename Dx >
stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, fvar< Dx > >::operands_and_partials ( const Op1 &  o1,
const Op2 &  o2,
const Op3 &  o3,
const Op4 &  o4,
const Op5 &  o5 
)
inline

Definition at line 83 of file operands_and_partials.hpp.

Member Function Documentation

◆ build()

template<typename Op1 , typename Op2 , typename Op3 , typename Op4 , typename Op5 , typename Dx >
T_return_type stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, fvar< Dx > >::build ( Dx  value)
inline

Build the node to be stored on the autodiff graph.

This should contain both the value and the tangent.

For scalars, we don't calculate any tangents. 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.

Parameters
valuethe return value of the function we are compressing
Returns
the value with its derivative

Definition at line 100 of file operands_and_partials.hpp.

Member Data Documentation

◆ edge1_

template<typename Op1 , typename Op2 , typename Op3 , typename Op4 , typename Op5 , typename Dx >
internal::ops_partials_edge<Dx, Op1> stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, fvar< Dx > >::edge1_

Definition at line 69 of file operands_and_partials.hpp.

◆ edge2_

template<typename Op1 , typename Op2 , typename Op3 , typename Op4 , typename Op5 , typename Dx >
internal::ops_partials_edge<Dx, Op2> stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, fvar< Dx > >::edge2_

Definition at line 70 of file operands_and_partials.hpp.

◆ edge3_

template<typename Op1 , typename Op2 , typename Op3 , typename Op4 , typename Op5 , typename Dx >
internal::ops_partials_edge<Dx, Op3> stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, fvar< Dx > >::edge3_

Definition at line 71 of file operands_and_partials.hpp.

◆ edge4_

template<typename Op1 , typename Op2 , typename Op3 , typename Op4 , typename Op5 , typename Dx >
internal::ops_partials_edge<Dx, Op4> stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, fvar< Dx > >::edge4_

Definition at line 72 of file operands_and_partials.hpp.

◆ edge5_

template<typename Op1 , typename Op2 , typename Op3 , typename Op4 , typename Op5 , typename Dx >
internal::ops_partials_edge<Dx, Op5> stan::math::operands_and_partials< Op1, Op2, Op3, Op4, Op5, fvar< Dx > >::edge5_

Definition at line 73 of file operands_and_partials.hpp.


The documentation for this class was generated from the following file:

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