| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

sum.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_ARR_FUN_SUM_HPP
2 #define STAN_MATH_FWD_ARR_FUN_SUM_HPP
3
4 #include <stan/math/fwd/core.hpp>
5 #include <stan/math/prim/arr/fun/sum.hpp>
6 #include <vector>
7
8 namespace stan {
9 namespace math {
10
19 template <typename T>
20 inline fvar<T> sum(const std::vector<fvar<T> >& m) {
21 if (m.size() == 0)
22 return 0.0;
23 std::vector<T> vals(m.size());
24 std::vector<T> tans(m.size());
25 for (size_t i = 0; i < m.size(); ++i) {
26 vals[i] = m[i].val();
27 tans[i] = m[i].tangent();
28 }
29 return fvar<T>(sum(vals), sum(tans));
30 }
31
32 }
33 }
34 #endif
stan::math::sum
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
Definition: sum.hpp:20
core.hpp
stan
Definition: log_sum_exp.hpp:8
sum.hpp
stan::math::fvar
Definition: fvar.hpp:12

[ Stan Home Page ] © 2011–2016, Stan Development Team.