Stan
1.3
probability, sampling & optimization
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerator
Friends
Macros
Pages
src
stan
math
matrix
sd.hpp
Go to the documentation of this file.
1
#ifndef __STAN__MATH__MATRIX__SD_HPP__
2
#define __STAN__MATH__MATRIX__SD_HPP__
3
4
#include <vector>
5
#include <boost/math/tools/promotion.hpp>
6
#include <
stan/math/matrix/Eigen.hpp
>
7
#include <
stan/math/matrix/variance.hpp
>
8
#include <
stan/math/matrix/validate_nonzero_size.hpp
>
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
validate_nonzero_size
(v,
"sd"
);
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
validate_nonzero_size
(m,
"sd"
);
40
if
(m.size() == 1)
return
0.0;
41
return
sqrt
(
variance
(m));
42
}
43
44
}
45
}
46
#endif
[
Stan Home Page
]
© 2011–2013, Stan Development Team.