Automatic Differentiation
 
Loading...
Searching...
No Matches
stan::math::accumulator< T, require_var_t< T > > Class Template Reference

Detailed Description

template<typename T>
class stan::math::accumulator< T, require_var_t< T > >

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.

Template Parameters
TType 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
 

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