Stan Math Library
5.0.0
Automatic Differentiation
|
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 autodiff 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 24 of file accumulator.hpp.
#include <accumulator.hpp>
Public Member Functions | |
template<typename S , typename = require_stan_scalar_t<S>> | |
void | add (S x) |
Add the specified arithmetic type value to the buffer after static casting it to the class type T . | |
template<typename S , require_matrix_t< S > * = nullptr> | |
void | add (const S &m) |
Add each entry in the specified matrix, vector, or row vector of values to the buffer. | |
template<typename S > | |
void | add (const std::vector< S > &xs) |
Recursively add each entry in the specified standard vector to the buffer. | |
template<typename S , require_all_kernel_expressions_and_none_scalar_t< S > * = nullptr> | |
void | add (const S &xs) |
Sum each entry and then push to the buffer. | |
T | sum () const |
Return the sum of the accumulated values. | |
Private Attributes | |
std::vector< T > | buf_ |