Stan Math Library: stan/math/prim/mat/fun/mean.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/arr/err/check_nonzero_size.hpp>
5 #include <stan/math/prim/mat/fun/Eigen.hpp>
6 #include <boost/math/tools/promotion.hpp>
7 #include <vector>
8
9 namespace stan {
10 namespace math {
11
20 template <typename T>
21 inline
22 typename boost::math::tools::promote_args<T>::type
23 mean(const std::vector<T>& v) {
24 stan::math::check_nonzero_size("mean", "v", v);
25 T sum(v[0]);
26 for (size_t i = 1; i < v.size(); ++i)
27 sum += v[i];
28 return sum / v.size();
29 }
30
37 template <typename T, int R, int C>
38 inline
39 typename boost::math::tools::promote_args<T>::type
40 mean(const Eigen::Matrix<T, R, C>& m) {
41 stan::math::check_nonzero_size("mean", "m", m);
42 return m.mean();
43 }
44
45 }
46 }
47 #endif
stan::math::sum
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
Definition: sum.hpp:20
stan
Definition: log_sum_exp.hpp:8
stan::math::check_nonzero_size
bool check_nonzero_size(const char *function, const char *name, const T_y &y)
Return true if the specified matrix/vector is of non-zero size.
Definition: check_nonzero_size.hpp:30
stan::math::mean
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:23
Eigen.hpp
check_nonzero_size.hpp

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