Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sum.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__FWD__MATRIX__SUM_HPP
2 #define STAN__AGRAD__FWD__MATRIX__SUM_HPP
3 
4 #include <vector>
7 
8 namespace stan {
9  namespace agrad {
10 
11  template <typename T, int R, int C>
12  inline
13  fvar<T>
14  sum(const Eigen::Matrix<fvar<T>,R,C>& m) {
15  fvar<T> sum = 0;
16  if (m.size() == 0)
17  return 0.0;
18  for(unsigned i = 0; i < m.rows(); i++) {
19  for(unsigned j = 0; j < m.cols(); j++)
20  sum += m(i,j);
21  }
22  return sum;
23  }
24  }
25 }
26 #endif
fvar< T > sum(const Eigen::Matrix< fvar< T >, R, C > &m)
Definition: sum.hpp:14

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