Stan Math Library  2.11.0
reverse mode automatic differentiation
prod.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_PROD_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_PROD_HPP
3 
5 #include <vector>
6 
7 namespace stan {
8  namespace math {
9 
16  template <typename T>
17  inline T prod(const std::vector<T>& v) {
18  if (v.size() == 0) return 1;
19  T product = v[0];
20  for (size_t i = 1; i < v.size(); ++i)
21  product *= v[i];
22  return product;
23  }
24 
31  template <typename T, int R, int C>
32  inline T prod(const Eigen::Matrix<T, R, C>& v) {
33  if (v.size() == 0) return 1.0;
34  return v.prod();
35  }
36 
37  }
38 }
39 #endif
T prod(const std::vector< T > &v)
Returns the product of the coefficients of the specified standard vector.
Definition: prod.hpp:17

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