Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
check_pos_definite.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_POS_DEFINITE_HPP
2 #define STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_POS_DEFINITE_HPP
3 
4 #include <sstream>
9 
10 namespace stan {
11 
12  namespace math {
13 
27  // FIXME: update warnings (message has (0,0) item)
28  template <typename T_y, typename T_result>
29  inline bool check_pos_definite(const char* function,
30  const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& y,
31  const char* name,
32  T_result* result) {
33  if (y.rows() == 1 && !(y(0,0) > CONSTRAINT_TOLERANCE)) {
34  std::ostringstream message;
35  message << name << " is not positive definite. "
36  << name << "(0,0) is %1%.";
37  std::string msg(message.str());
38  return dom_err(function,y(0,0),name,msg.c_str(),"",result);
39  }
40  for (int i = 0; i < y.size(); ++i)
41  check_not_nan(function, y(i), "", result);
42 
43  Eigen::LDLT< Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic> > cholesky
44  = y.ldlt();
45  if (cholesky.info() != Eigen::Success
46  || !cholesky.isPositive()
47  || (cholesky.vectorD().array() <= CONSTRAINT_TOLERANCE).any()) {
48  std::ostringstream message;
49  message << name << " is not positive definite. "
50  << name << "(0,0) is %1%.";
51  std::string msg(message.str());
52  return dom_err(function,y(0,0),name,msg.c_str(),"",result);
53  }
54  return true;
55  }
56 
57  }
58 }
59 #endif
bool dom_err(const char *function, const T &y, const char *name, const char *error_msg, const T_msg error_msg2, T_result *result)
Definition: dom_err.hpp:36
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds In rank and in simplexes.
bool check_pos_definite(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name, T_result *result)
Return true if the specified matrix is positive definite.
bool check_not_nan(const char *function, const T_y &y, const char *name, T_result *result)
Checks if the variable y is nan.

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