Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
mean.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__MATRIX__MEAN_HPP__
2 #define __STAN__MATH__MATRIX__MEAN_HPP__
3 
4 #include <vector>
5 #include <boost/math/tools/promotion.hpp>
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  validate_nonzero_size(v,"mean");
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  validate_nonzero_size(m,"mean");
42  return m.mean();
43  }
44 
45  }
46 }
47 #endif

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