Stan Math Library: stan/math/prim/mat/err/check_pos_semidefinite.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

check_pos_semidefinite.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_POS_SEMIDEFINITE_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_POS_SEMIDEFINITE_HPP
3
4 #include <stan/math/prim/scal/err/domain_error.hpp>
5 #include <stan/math/prim/mat/err/check_symmetric.hpp>
6 #include <stan/math/prim/mat/err/constraint_tolerance.hpp>
7 #include <stan/math/prim/scal/err/check_not_nan.hpp>
8 #include <stan/math/prim/scal/err/check_positive_size.hpp>
9 #include <stan/math/prim/mat/fun/Eigen.hpp>
10 #include <stan/math/prim/mat/meta/index_type.hpp>
11 #include <stan/math/prim/mat/fun/value_of_rec.hpp>
12 #include <sstream>
13
14 namespace stan {
15
16 namespace math {
33 template <typename T_y>
34 inline bool
35 check_pos_semidefinite(
36 const char* function,
37 const char* name,
38 const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y
39 ) {
40 check_symmetric(function, name, y);
41 check_positive_size(function, name, "rows", y.rows());
42
43 if (y.rows() == 1 && !(y(0, 0) >= 0.0))
44 domain_error(function, name, y, "is not positive semi-definite: ");
45
46 using Eigen::LDLT;
47 using Eigen::Matrix;
48 using Eigen::Dynamic;
49 LDLT<Matrix<double, Dynamic, Dynamic> > cholesky
50 = value_of_rec(y).ldlt();
51 if (cholesky.info() != Eigen::Success
52 || (cholesky.vectorD().array() < 0.0).any())
53 domain_error(function, name, y, "is not positive semi-definite:\n");
54 check_not_nan(function, name, y);
55 return true;
56 }
57
58 }
59 }
60 #endif
check_not_nan.hpp
value_of_rec.hpp
stan::math::check_not_nan
bool check_not_nan(const char *function, const char *name, const T_y &y)
Return true if y is not NaN.
Definition: check_not_nan.hpp:63
stan::math::check_positive_size
bool check_positive_size(const char *function, const char *name, const char *expr, const int size)
Return true if size is positive.
Definition: check_positive_size.hpp:23
stan
Definition: log_sum_exp.hpp:8
stan::math::value_of_rec
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
Definition: value_of_rec.hpp:21
constraint_tolerance.hpp
check_symmetric.hpp
stan::math::check_pos_semidefinite
bool check_pos_semidefinite(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is positive definite.
Definition: check_pos_semidefinite.hpp:35
index_type.hpp
stan::math::domain_error
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
Definition: domain_error.hpp:32
Eigen.hpp
domain_error.hpp
stan::math::check_symmetric
bool check_symmetric(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is symmetric.
Definition: check_symmetric.hpp:37
check_positive_size.hpp

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