Automatic Differentiation
 
Loading...
Searching...
No Matches
sum.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_SUM_HPP
2#define STAN_MATH_PRIM_FUN_SUM_HPP
3
6#include <cstddef>
7#include <numeric>
8#include <vector>
9
10namespace stan {
11namespace math {
12
20template <typename T, require_stan_scalar_t<T>* = nullptr>
21inline T sum(T&& m) {
22 return std::forward<T>(m);
23}
24
32template <typename T, require_not_autodiff_t<T>* = nullptr>
33inline T sum(const std::vector<T>& m) {
34 return std::accumulate(m.begin(), m.end(), T{0});
35}
36
45template <typename T, require_eigen_vt<std::is_arithmetic, T>* = nullptr>
46inline value_type_t<T> sum(const T& m) {
47 return m.sum();
48}
49
58template <typename T, require_eigen_vt<is_complex, T>* = nullptr>
59inline value_type_t<T> sum(const T& m) {
60 return m.sum();
61}
62
63} // namespace math
64} // namespace stan
65
66#endif
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
Definition sum.hpp:23
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...