Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs 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  namespace math {
12 
25  // FIXME: update warnings (message has (0,0) item)
26  template <typename T_y, typename T_result, class Policy>
27  inline bool check_pos_definite(const char* function,
28  const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& y,
29  const char* name,
30  T_result* result,
31  const Policy&) {
32  typedef
34  size_type;
35  if (y.rows() == 1 && y(0,0) <= CONSTRAINT_TOLERANCE) {
36  std::ostringstream message;
37  message << name << " is not positive definite. "
38  << name << "(0,0) is %1%.";
39  T_result tmp = policies::raise_domain_error<T_y>(function,
40  message.str().c_str(),
41  y(0,0), Policy());
42  if (result != 0)
43  *result = tmp;
44  return false;
45  }
46  Eigen::LDLT< Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic> > cholesky
47  = y.ldlt();
48  if(cholesky.info() != Eigen::Success ||
49  cholesky.isNegative() ||
50  (cholesky.vectorD().array() <= CONSTRAINT_TOLERANCE).any()) {
51  std::ostringstream message;
52  message << name << " is not positive definite. "
53  << name << "(0,0) is %1%.";
54  T_result tmp = policies::raise_domain_error<T_y>(function,
55  message.str().c_str(),
56  y(0,0), Policy());
57  if (result != 0)
58  *result = tmp;
59  return false;
60  }
61  return true;
62  }
63 
64 
65  template <typename T_y, typename T_result>
66  inline bool check_pos_definite(const char* function,
67  const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& y,
68  const char* name,
69  T_result* result) {
70  return check_pos_definite(function,y,name,result,default_policy());
71  }
72 
73 
74  template <typename T>
75  inline bool check_pos_definite(const char* function,
76  const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>& y,
77  const char* name,
78  T* result = 0) {
79  return check_pos_definite(function,y,name,result,default_policy());
80  }
81 
82  }
83 }
84 #endif

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