Automatic Differentiation
 
Loading...
Searching...
No Matches

◆ operator()()

template<typename ReduceFunction , typename ReturnType , typename Vec , typename... Args>
var stan::math::internal::reduce_sum_impl< ReduceFunction, require_var_t< ReturnType >, ReturnType, Vec, Args... >::operator() ( Vec &&  vmapped,
bool  auto_partitioning,
int  grainsize,
std::ostream *  msgs,
Args &&...  args 
) const
inline

Call an instance of the function ReduceFunction on every element of an input sequence and sum these terms.

This specialization is parallelized using tbb and works for reverse mode autodiff.

ReduceFunction must define an operator() with the same signature as: var f(Vec&& vmapped_subset, int start, int end, std::ostream* msgs, Args&&... args)

ReduceFunction must be default constructible without any arguments

Each call to ReduceFunction is responsible for computing the start through end (inclusive) terms of the overall sum. All args are passed from this function through to the ReduceFunction instances. However, only the start through end (inclusive) elements of the vmapped argument are passed to the ReduceFunction instances (as the vmapped_subset argument).

This function distributes computation of the desired sum and the Jacobian of that sum over multiple threads by coordinating calls to ReduceFunction instances. Results are stored as precomputed varis in the autodiff tree.

If auto partitioning is true, break work into pieces automatically, taking grainsize as a recommended work size. The partitioning is not deterministic nor is the order guaranteed in which partial sums are accumulated. Due to floating point imprecisions this will likely lead to slight differences in the accumulated results between multiple runs. If false, break work deterministically into pieces smaller than or equal to grainsize and accumulate all the partial sums in the same order. This still may not achieve bitwise reproducibility.

Parameters
vmappedVector containing one element per term of sum
auto_partitioningWork partitioning style
grainsizeSuggested grainsize for tbb
[in,out]msgsThe print stream for warning messages
argsShared arguments used in every sum term
Returns
Summation of all terms

Definition at line 224 of file reduce_sum.hpp.