Automatic Differentiation
 
Loading...
Searching...
No Matches
sd.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_SD_HPP
2#define STAN_MATH_PRIM_FUN_SD_HPP
3
8#include <vector>
9#include <cmath>
10
11namespace stan {
12namespace math {
13
24template <typename T, require_container_t<T>* = nullptr,
25 require_not_st_var<T>* = nullptr>
26inline auto sd(const T& m) {
27 using std::sqrt;
28
29 return apply_vector_unary<T>::reduce(m, [](const auto& x) {
30 check_nonzero_size("sd", "x", x);
31
32 if (x.size() == 1) {
33 return scalar_type_t<T>(0.0);
34 }
35
36 return sqrt(variance(x));
37 });
38}
39
40} // namespace math
41} // namespace stan
42
43#endif
double variance(const T &a)
Return the sample variance of the var_value matrix Raise domain error if size is not greater than zer...
Definition variance.hpp:25
fvar< T > sqrt(const fvar< T > &x)
Definition sqrt.hpp:17
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.
double sd(const T &a)
Returns the unbiased sample standard deviation of the coefficients in the specified std vector,...
Definition sd.hpp:26
typename scalar_type< T >::type scalar_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...