![]() |
Stan Math Library
2.11.0
reverse mode automatic differentiation
|
Class to accumulate values and eventually return their sum. More...
#include <accumulator.hpp>
Public Member Functions | |
| accumulator () | |
| Construct an accumulator. More... | |
| ~accumulator () | |
| Destroy an accumulator. More... | |
| template<typename S > | |
| boost::enable_if< boost::is_arithmetic< S >, void >::type | add (S x) |
Add the specified arithmetic type value to the buffer after static casting it to the class type T. More... | |
| template<typename S > | |
| boost::disable_if< boost::is_arithmetic< S >, typename boost::enable_if< boost::is_same< S, T >, void >::type >::type | add (const S &x) |
| Add the specified non-arithmetic value to the buffer. More... | |
| template<typename S , int R, int C> | |
| void | add (const Eigen::Matrix< S, R, C > &m) |
| Add each entry in the specified matrix, vector, or row vector of values to the buffer. More... | |
| template<typename S > | |
| void | add (const std::vector< S > &xs) |
| Recursively add each entry in the specified standard vector to the buffer. More... | |
| T | sum () const |
| Return the sum of the accumulated values. More... | |
Class to accumulate values and eventually return their sum.
If no values are ever added, the return value is 0.
This class is useful for speeding up auto-diff of long sums because it uses the sum() operation (either from stan::math or one defined by argument-dependent lookup.
| T | Type of scalar added |
Definition at line 25 of file accumulator.hpp.
|
inline |
Construct an accumulator.
Definition at line 33 of file accumulator.hpp.
|
inline |
Destroy an accumulator.
Definition at line 40 of file accumulator.hpp.
|
inline |
Add the specified arithmetic type value to the buffer after static casting it to the class type T.
See the Boost doc for boost::is_arithmetic for information on what counts as an arithmetic type.
| S | Type of argument |
| x | Value to add |
Definition at line 54 of file accumulator.hpp.
|
inline |
Add the specified non-arithmetic value to the buffer.
This function is disabled if the type S is arithmetic or if it's not the same as T.
See the Boost doc for boost::is_arithmetic for information on what counts as an arithmetic type.
| S | Type of argument |
| x | Value to add |
Definition at line 74 of file accumulator.hpp.
|
inline |
Add each entry in the specified matrix, vector, or row vector of values to the buffer.
| S | type of values in matrix |
| R | number of rows in matrix |
| C | number of columns in matrix |
| m | Matrix of values to add |
Definition at line 88 of file accumulator.hpp.
|
inline |
Recursively add each entry in the specified standard vector to the buffer.
This will allow vectors of primitives, auto-diff variables to be added; if the vector entries are collections, their elements are recursively added.
| S | Type of value to recursively add. |
| xs | Vector of entries to add |
Definition at line 103 of file accumulator.hpp.
|
inline |
Return the sum of the accumulated values.
Definition at line 113 of file accumulator.hpp.