Stan Math Library  2.9.0
reverse mode automatic differentiation
sd.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_SD_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_SD_HPP
3 
7 #include <boost/math/tools/promotion.hpp>
8 #include <vector>
9 
10 namespace stan {
11  namespace math {
12 
19  template <typename T>
20  inline
21  typename boost::math::tools::promote_args<T>::type
22  sd(const std::vector<T>& v) {
23  stan::math::check_nonzero_size("sd", "v", v);
24  if (v.size() == 1) return 0.0;
25  return sqrt(variance(v));
26  }
27 
34  template <typename T, int R, int C>
35  inline
36  typename boost::math::tools::promote_args<T>::type
37  sd(const Eigen::Matrix<T, R, C>& m) {
38  // FIXME: redundant with test in variance; second line saves sqrt
39  stan::math::check_nonzero_size("sd", "m", m);
40  if (m.size() == 1) return 0.0;
41  return sqrt(variance(m));
42  }
43 
44  }
45 }
46 #endif
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:15
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.
boost::math::tools::promote_args< T >::type sd(const std::vector< T > &v)
Returns the unbiased sample standard deviation of the coefficients in the specified column vector...
Definition: sd.hpp:22
boost::math::tools::promote_args< T >::type variance(const std::vector< T > &v)
Returns the sample variance (divide by length - 1) of the coefficients in the specified standard vect...
Definition: variance.hpp:24

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