Stan Math Library  2.15.0
reverse mode automatic differentiation
num_elements.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_NUM_ELEMENTS_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_NUM_ELEMENTS_HPP
3 
5 #include <vector>
6 
7 namespace stan {
8  namespace math {
9 
16  template <typename T>
17  inline int
18  num_elements(const T& x) {
19  return 1;
20  }
21 
28  template <typename T, int R, int C>
29  inline int
30  num_elements(const Eigen::Matrix<T, R, C>& m) {
31  return m.size();
32  }
33 
42  template <typename T>
43  inline int
44  num_elements(const std::vector<T>& v) {
45  if (v.size() == 0)
46  return 0;
47  return v.size() * num_elements(v[0]);
48  }
49 
50  }
51 }
52 #endif
int num_elements(const T &x)
Returns 1, the number of elements in a primitive type.

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