Automatic Differentiation
 
Loading...
Searching...
No Matches
prod.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_PROD_HPP
2#define STAN_MATH_PRIM_FUN_PROD_HPP
3
6#include <vector>
7
8namespace stan {
9namespace math {
10
18template <typename T, require_stan_scalar_t<T>* = nullptr>
19T prod(const T& v) {
20 return v;
21}
22
31template <typename T>
32inline T prod(const std::vector<T>& v) {
33 if (v.size() == 0) {
34 return 1;
35 }
36 Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> m(&v[0], v.size());
37 return m.prod();
38}
39
48template <typename EigMat, require_eigen_t<EigMat>* = nullptr>
49inline value_type_t<EigMat> prod(const EigMat& v) {
50 if (v.size() == 0) {
51 return 1.0;
52 }
53 return v.prod();
54}
55
56} // namespace math
57} // namespace stan
58
59#endif
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
value_type_t< T > prod(const T &m)
Calculates product of given kernel generator expression elements.
Definition prod.hpp:21
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9