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

Detailed Description

template<typename T, typename = void>
class stan::math::accumulator< T, typename >

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 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.
 
sum () const
 Return the sum of the accumulated values.
 

Private Attributes

std::vector< T > buf_
 

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