| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
sum.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_MAT_FUN_SUM_HPP
2 #define STAN_MATH_FWD_MAT_FUN_SUM_HPP
3
4 #include <stan/math/fwd/core.hpp>
5 #include <stan/math/prim/mat/fun/Eigen.hpp>
6 #include <stan/math/prim/mat/fun/sum.hpp>
7
8 namespace stan {
9 namespace math {
10
20 template <typename T, int R, int C>
21 inline fvar<T> sum(const Eigen::Matrix<fvar<T>, R, C>& m) {
22 using stan::math::sum;
23 if (m.size() == 0)
24 return 0.0;
25 Eigen::Matrix<T, Eigen::Dynamic, 1> vals(m.size());
26 Eigen::Matrix<T, Eigen::Dynamic, 1> tans(m.size());
27 for (int i = 0; i < m.size(); ++i) {
28 vals(i) = m(i).val();
29 tans(i) = m(i).tangent();
30 }
31 return fvar<T>(sum(vals), sum(tans));
32 }
33
34 }
35 }
36 #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
Eigen.hpp
sum.hpp
stan::math::fvar
Definition: fvar.hpp:13

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