Stan Math Library  2.15.0
reverse mode automatic differentiation
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 
12 #include <sstream>
13 
14 namespace stan {
15  namespace math {
16 
32  template <typename T_y>
33  inline void
34  check_pos_semidefinite(const char* function,
35  const char* name,
36  const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y) {
37  check_symmetric(function, name, y);
38  check_positive_size(function, name, "rows", y.rows());
39 
40  if (y.rows() == 1 && !(y(0, 0) >= 0.0))
41  domain_error(function, name, "is not positive semi-definite.", "");
42 
43  using Eigen::LDLT;
44  using Eigen::Matrix;
45  using Eigen::Dynamic;
46  LDLT<Matrix<double, Dynamic, Dynamic> > cholesky
47  = value_of_rec(y).ldlt();
48  if (cholesky.info() != Eigen::Success
49  || (cholesky.vectorD().array() < 0.0).any())
50  domain_error(function, name, "is not positive semi-definite.", "");
51  check_not_nan(function, name, y);
52  }
53 
54  }
55 }
56 #endif
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
void check_positive_size(const char *function, const char *name, const char *expr, int size)
Check if size is positive.
void check_pos_semidefinite(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Check if the specified matrix is positive definite.
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
void check_symmetric(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Check if the specified matrix is symmetric.
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.

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