check_pos_definite.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_POS_DEFINITE_HPP
#define STAN_MATH_PRIM_MAT_ERR_CHECK_POS_DEFINITE_HPP
#include <stan/math/prim/mat/meta/get.hpp>
#include <stan/math/prim/mat/meta/length.hpp>
#include <stan/math/prim/mat/meta/is_vector.hpp>
#include <stan/math/prim/mat/meta/is_vector_like.hpp>
#include <stan/math/prim/scal/err/check_not_nan.hpp>
#include <stan/math/prim/scal/err/domain_error.hpp>
#include <stan/math/prim/mat/err/check_symmetric.hpp>
#include <stan/math/prim/mat/err/constraint_tolerance.hpp>
#include <stan/math/prim/scal/err/check_positive_size.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/fun/value_of_rec.hpp>
namespace stan {
namespace math {
template <typename T_y>
inline void check_pos_definite(const char* function, const char* name,
const Eigen::Matrix<T_y, -1, -1>& y) {
check_symmetric(function, name, y);
check_positive_size(function, name, "rows", y.rows());
if (y.rows() == 1 && !(y(0, 0) > CONSTRAINT_TOLERANCE))
domain_error(function, name, "is not positive definite.", "");
Eigen::LDLT<Eigen::MatrixXd> cholesky = value_of_rec(y).ldlt();
if (cholesky.info() != Eigen::Success
|| !cholesky.isPositive()
|| (cholesky.vectorD().array() <= 0.0).any())
domain_error(function, name, "is not positive definite.", "");
check_not_nan(function, name, y);
}
template <typename Derived>
inline void check_pos_definite(const char* function, const char* name,
const Eigen::LDLT<Derived>& cholesky) {
if (cholesky.info() != Eigen::Success
|| !cholesky.isPositive()
|| !(cholesky.vectorD().array() > 0.0).all())
domain_error(function, "LDLT decomposition of", " failed", name);
}
template <typename Derived>
inline void check_pos_definite(const char* function, const char* name,
const Eigen::LLT<Derived>& cholesky) {
if (cholesky.info() != Eigen::Success
|| !(cholesky.matrixLLT().diagonal().array() > 0.0).all())
domain_error(function, "Matrix", " is not positive definite", name);
}
}
}
#endif
check_not_nan.hpp
value_of_rec.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::value_of_rec
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
Definition: value_of_rec.hpp:21
is_vector_like.hpp
stan::math::check_positive_size
void check_positive_size(const char *function, const char *name, const char *expr, int size)
Check if size is positive.
Definition: check_positive_size.hpp:22
get.hpp
length.hpp
is_vector.hpp
constraint_tolerance.hpp
check_symmetric.hpp
stan::math::CONSTRAINT_TOLERANCE
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds In rank and in simplexes.
Definition: constraint_tolerance.hpp:11
stan::math::check_not_nan
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
Definition: check_not_nan.hpp:57
stan::math::check_symmetric
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.
Definition: check_symmetric.hpp:35
stan::math::domain_error
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.
Definition: domain_error.hpp:30
Eigen.hpp
domain_error.hpp
stan::math::check_pos_definite
void check_pos_definite(const char *function, const char *name, const Eigen::Matrix< T_y, -1, -1 > &y)
Check if the specified square, symmetric matrix is positive definite.
Definition: check_pos_definite.hpp:33
check_positive_size.hpp

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