1 #ifndef STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_POS_SEMIDEFINITE_HPP
2 #define STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_POS_SEMIDEFINITE_HPP
6 #include <boost/math/special_functions/fpclassify.hpp>
31 template <
typename T_y,
typename T_result>
34 const Eigen::Matrix<T_y,
43 if (y.rows() == 1 && !(y(0,0) >= 0.0)) {
44 std::ostringstream message;
45 message << name <<
" is not positive semi-definite. "
46 << name <<
"(0,0) is %1%.";
47 std::string msg(message.str());
48 return dom_err(
function,y(0,0),name,msg.c_str(),
"",result);
50 Eigen::LDLT< Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic> > cholesky
52 if(cholesky.info() != Eigen::Success || (cholesky.vectorD().array() < 0.0).any()) {
53 std::ostringstream message;
54 message << name <<
" is not positive semi-definite. "
55 << name <<
"(0,0) is %1%.";
56 std::string msg(message.str());
57 return dom_err(
function,y(0,0),name,msg.c_str(),
"",result);
59 for (
int i = 0; i < y.size(); i++)
61 std::ostringstream message;
62 message << name <<
" is not positive semi-definite. "
63 << name <<
"(0,0) is %1%.";
64 std::string msg(message.str());
65 return dom_err(
function,y(0,0),name,msg.c_str(),
"",result);
bool isnan(const stan::agrad::var &v)
Checks if the given number is NaN.
bool dom_err(const char *function, const T &y, const char *name, const char *error_msg, const T_msg error_msg2, T_result *result)
bool check_pos_semidefinite(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.
Primary template class for the metaprogram to compute the index type of a container.
index_type< Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > >::type size_type
Type for sizes and indexes in an Eigen matrix with double e.