Stan Math Library  2.8.0
reverse mode automatic differentiation
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
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 
16  namespace math {
17  using Eigen::Dynamic;
34  template <typename T_y>
35  inline bool
36  check_pos_semidefinite(const char* function,
37  const char* name,
38  const Eigen::Matrix<T_y, Dynamic, Dynamic>& y) {
39  check_symmetric(function, name, y);
40  check_positive_size(function, name, "rows", y.rows());
41 
42  if (y.rows() == 1 && !(y(0, 0) >= 0.0))
43  domain_error(function, name, y, "is not positive semi-definite: ");
44 
45  using Eigen::LDLT;
46  using Eigen::Matrix;
47  using Eigen::Dynamic;
48  LDLT<Matrix<double, Dynamic, Dynamic> > cholesky
49  = value_of_rec(y).ldlt();
50  if (cholesky.info() != Eigen::Success
51  || (cholesky.vectorD().array() < 0.0).any())
52  domain_error(function, name, y, "is not positive semi-definite:\n");
53  check_not_nan(function, name, y);
54  return true;
55  }
56 
57  }
58 }
59 #endif
bool check_not_nan(const char *function, const char *name, const T_y &y)
Return true if y is not NaN.
bool check_positive_size(const char *function, const char *name, const char *expr, const int size)
Return true if size is positive.
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
bool check_pos_semidefinite(const char *function, const char *name, const Eigen::Matrix< T_y, Dynamic, Dynamic > &y)
Return true if the specified matrix is positive definite.
bool check_symmetric(const char *function, const char *name, const Eigen::Matrix< T_y, Dynamic, Dynamic > &y)
Return true 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–2015, Stan Development Team.