Stan Math Library  2.20.0
reverse mode automatic differentiation
mean.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_MEAN_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_MEAN_HPP
3 
6 #include <boost/math/tools/promotion.hpp>
7 #include <vector>
8 
9 namespace stan {
10 namespace math {
11 
20 template <typename T>
21 inline typename boost::math::tools::promote_args<T>::type mean(
22  const std::vector<T>& v) {
23  check_nonzero_size("mean", "v", v);
24  Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> m(&v[0], v.size());
25  return m.mean();
26 }
27 
34 template <typename T, int R, int C>
35 inline typename boost::math::tools::promote_args<T>::type mean(
36  const Eigen::Matrix<T, R, C>& m) {
37  check_nonzero_size("mean", "m", m);
38  return m.mean();
39 }
40 
41 } // namespace math
42 } // namespace stan
43 #endif
void check_nonzero_size(const char *function, const char *name, const T_y &y)
Check if the specified matrix/vector is of non-zero size.
boost::math::tools::promote_args< T >::type mean(const std::vector< T > &v)
Returns the sample mean (i.e., average) of the coefficients in the specified standard vector...
Definition: mean.hpp:21

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