Automatic Differentiation
 
Loading...
Searching...
No Matches
reduce_sum_static.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUNCTOR_REDUCE_SUM_STATIC_HPP
2#define STAN_MATH_PRIM_FUNCTOR_REDUCE_SUM_STATIC_HPP
3
7#include <tbb/task_arena.h>
8#include <tbb/parallel_reduce.h>
9#include <tbb/blocked_range.h>
10
11#include <tuple>
12#include <vector>
13
14namespace stan {
15namespace math {
16
43template <typename ReduceFunction, typename Vec,
44 typename = require_vector_like_t<Vec>, typename... Args>
45auto reduce_sum_static(Vec&& vmapped, int grainsize, std::ostream* msgs,
46 Args&&... args) {
47 using return_type = return_type_t<Vec, Args...>;
48
49 check_positive("reduce_sum", "grainsize", grainsize);
50
51#ifdef STAN_THREADS
52 return internal::reduce_sum_impl<ReduceFunction, void, return_type, Vec,
53 Args...>()(std::forward<Vec>(vmapped), false,
54 grainsize, msgs,
55 std::forward<Args>(args)...);
56#else
57 if (vmapped.empty()) {
58 return return_type(0);
59 }
60
61 return ReduceFunction()(std::forward<Vec>(vmapped), 0, vmapped.size() - 1,
62 msgs, std::forward<Args>(args)...);
63#endif
64}
65
66} // namespace math
67} // namespace stan
68
69#endif
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
auto reduce_sum_static(Vec &&vmapped, int grainsize, std::ostream *msgs, Args &&... args)
Call an instance of the function ReduceFunction on every element of an input sequence and sum these t...
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
reduce_sum_impl implementation for any autodiff type.
Template metaprogram to calculate the base scalar return type resulting from promoting all the scalar...