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 
10 /**
11  * Returns the product of the coefficients of the specified
12  * standard vector.
13  * @param v Specified vector.
14  * @return Product of coefficients of vector.
15  */
16 template <typename T>
17 inline T prod(const std::vector<T>& v) {
18  if (v.size() == 0)
19  return 1;
20  T product = v[0];
21  for (size_t i = 1; i < v.size(); ++i)
22  product *= v[i];
23  return product;
24 }
25 
26 /**
27  * Returns the product of the coefficients of the specified
28  * column vector.
29  * @param v Specified vector.
30  * @return Product of coefficients of vector.
31  */
32 template <typename T, int R, int C>
33 inline T prod(const Eigen::Matrix<T, R, C>& v) {
34  if (v.size() == 0)
35  return 1.0;
36  return v.prod();
37 }
38 
39 } // namespace math
40 } // namespace stan
41 #endif
T prod(const std::vector< T > &v)
Definition: prod.hpp:17
T product(std::vector< T > dims)
double T
Definition: Xdiff_gwt.C:5