All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
mean.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_FUN_MEAN_HPP
#define STAN_MATH_PRIM_MAT_FUN_MEAN_HPP
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/scal/err/check_nonzero_size.hpp>
#include <boost/math/tools/promotion.hpp>
#include <vector>
namespace stan {
namespace math {
template <typename T>
inline
typename boost::math::tools::promote_args<T>::type
mean(const std::vector<T>& v) {
stan::math::check_nonzero_size("mean", "v", v);
T sum(v[0]);
for (size_t i = 1; i < v.size(); ++i)
sum += v[i];
return sum / v.size();
}
template <typename T, int R, int C>
inline
typename boost::math::tools::promote_args<T>::type
mean(const Eigen::Matrix<T, R, C>& m) {
stan::math::check_nonzero_size("mean", "m", m);
return m.mean();
}
}
}
#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::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:31
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–2015, Stan Development Team.