Stan Math Library  2.20.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 typename boost::math::tools::promote_args<T>::type sd(
21  const std::vector<T>& v) {
22  check_nonzero_size("sd", "v", v);
23  if (v.size() == 1)
24  return 0.0;
25  return sqrt(variance(v));
26 }
27 
34 template <typename T, int R, int C>
35 inline typename boost::math::tools::promote_args<T>::type sd(
36  const Eigen::Matrix<T, R, C>& m) {
37  check_nonzero_size("sd", "m", m);
38  if (m.size() == 1)
39  return 0.0;
40  return sqrt(variance(m));
41 }
42 
43 } // namespace math
44 } // namespace stan
45 #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.
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:13
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:20
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:22

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