#ifndef STAN_MATH_PRIM_FUN_SD_HPP #define STAN_MATH_PRIM_FUN_SD_HPP #include #include #include #include #include #include namespace stan { namespace math { /** * Returns the unbiased sample standard deviation of the * coefficients in the specified std vector, column vector, row vector, or * matrix. * * @tparam T type of the container * * @param m Specified container. * @return Sample variance. */ template * = nullptr, require_not_st_var* = nullptr> inline auto sd(const T& m) { using std::sqrt; return apply_vector_unary::reduce(m, [](const auto& x) { check_nonzero_size("sd", "x", x); if (x.size() == 1) { return scalar_type_t(0.0); } return sqrt(variance(x)); }); } } // namespace math } // namespace stan #endif