Stan Math Library
4.8.1
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 25 of file accumulator.hpp.
#include <accumulator.hpp>
Public Member Functions | |
accumulator () | |
Constructor. | |
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 , require_std_vector_vt< is_stan_scalar, S > * = nullptr> | |
void | add (const S &xs) |
Add each entry in the specified std vector of values to the buffer. | |
template<typename S , require_std_vector_vt< is_container_or_var_matrix, S > * = nullptr> | |
void | add (const S &xs) |
Recursively add each entry in the specified standard vector containint containers to the buffer. | |
template<typename S , require_all_kernel_expressions_and_none_scalar_t< S > * = nullptr> | |
void | add (const var_value< S > &xs) |
Sum each entry and then push 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. | |
var | sum () const |
Return the sum of the accumulated values. | |
Private Member Functions | |
void | check_size () |
Checks if the internal buffer is full and if so reduces it to 1 element. | |
Private Attributes | |
std::vector< var, arena_allocator< var > > | buf_ |
Static Private Attributes | |
static constexpr int | max_size_ = 128 |