All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
check_pos_semidefinite.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_POS_SEMIDEFINITE_HPP
#define STAN_MATH_PRIM_MAT_ERR_CHECK_POS_SEMIDEFINITE_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_not_nan.hpp>
#include <stan/math/prim/scal/err/check_positive_size.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/meta/index_type.hpp>
#include <stan/math/prim/mat/fun/value_of_rec.hpp>
#include <sstream>
namespace stan {
namespace math {
using Eigen::Dynamic;
template <typename T_y>
inline bool
check_pos_semidefinite(const char* function,
const char* name,
const Eigen::Matrix<T_y, Dynamic, Dynamic>& y) {
check_symmetric(function, name, y);
check_positive_size(function, name, "rows", y.rows());
if (y.rows() == 1 && !(y(0, 0) >= 0.0))
domain_error(function, name, y, "is not positive semi-definite: ");
using Eigen::LDLT;
using Eigen::Matrix;
using Eigen::Dynamic;
LDLT<Matrix<double, Dynamic, Dynamic> > cholesky
= value_of_rec(y).ldlt();
if (cholesky.info() != Eigen::Success
|| (cholesky.vectorD().array() < 0.0).any())
domain_error(function, name, y, "is not positive semi-definite:\n");
check_not_nan(function, name, y);
return true;
}
}
}
#endif
check_not_nan.hpp
value_of_rec.hpp
stan::math::check_not_nan
bool check_not_nan(const char *function, const char *name, const T_y &y)
Return true if y is not NaN.
Definition: check_not_nan.hpp:63
stan::math::check_positive_size
bool check_positive_size(const char *function, const char *name, const char *expr, const int size)
Return true if size is positive.
Definition: check_positive_size.hpp:23
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
stan::math::check_pos_semidefinite
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.
Definition: check_pos_semidefinite.hpp:36
stan::math::check_symmetric
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.
Definition: check_symmetric.hpp:38
constraint_tolerance.hpp
check_symmetric.hpp
index_type.hpp
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:32
Eigen.hpp
domain_error.hpp
check_positive_size.hpp

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