Stan Math Library  2.20.0
reverse mode automatic differentiation
is_pos_definite.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_IS_POS_DEFINITE_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_IS_POS_DEFINITE_HPP
3 
11 
12 namespace stan {
13 namespace math {
14 
26 template <typename T_y>
27 inline bool is_pos_definite(const Eigen::Matrix<T_y, -1, -1>& y) {
28  if (!is_symmetric(y))
29  return false;
30  if (!is_positive(y.rows()))
31  return false;
32  if (y.rows() == 1 && !(y(0, 0) > CONSTRAINT_TOLERANCE))
33  return false;
34  Eigen::LDLT<Eigen::MatrixXd> cholesky = value_of_rec(y).ldlt();
35  if (cholesky.info() != Eigen::Success || !cholesky.isPositive()
36  || (cholesky.vectorD().array() <= 0.0).any())
37  return false;
38  return is_not_nan(y);
39 }
40 
50 template <typename Derived>
51 inline bool is_pos_definite(const Eigen::LDLT<Derived>& cholesky) {
52  return cholesky.info() == Eigen::Success && cholesky.isPositive()
53  && (cholesky.vectorD().array() > 0.0).all();
54 }
55 
65 template <typename Derived>
66 inline bool is_pos_definite(const Eigen::LLT<Derived>& cholesky) {
67  return cholesky.info() == Eigen::Success
68  && (cholesky.matrixLLT().diagonal().array() > 0.0).all();
69 }
70 
71 } // namespace math
72 } // namespace stan
73 #endif
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds In rank and in simplexes.
bool is_positive(const T_y &y)
Return true if y is positive.
Definition: is_positive.hpp:18
bool is_pos_definite(const Eigen::Matrix< T_y, -1, -1 > &y)
Return true if the matrix is square or if the matrix has non-zero size, or if the matrix is symmetric...
bool is_symmetric(const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the matrix is square, and no element not on the main diagonal is NaN.
bool is_not_nan(const T_y &y)
Return true if y is not NaN.
Definition: is_not_nan.hpp:21

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