check_ldlt_factor.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_LDLT_FACTOR_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_LDLT_FACTOR_HPP
3 
7 #include <sstream>
8 #include <string>
9 
10 namespace stan {
11 namespace math {
12 
13 /**
14  * Raise domain error if the specified LDLT factor is invalid. An
15  * <code>LDLT_factor</code> is invalid if it was constructed from
16  * a matrix that is not positive definite. The check is that the
17  * <code>success()</code> method returns <code>true</code>.
18  *
19  * @tparam T type of scalar
20  * @tparam R rows of the matrix
21  * @tparam C columns of the matrix
22  * @param[in] function function name for error messages
23  * @param[in] name variable name for error messages
24  * @param[in] A LDLT factor to check for validity
25  * @throws <code>std::domain_error</code> if the LDLT factor is
26  * invalid.
27  */
28 template <typename T, int R, int C>
29 inline void check_ldlt_factor(const char* function, const char* name,
31  if (!A.success()) {
32  std::ostringstream msg;
33  msg << "is not positive definite. last conditional variance is ";
34  std::string msg_str(msg.str());
35  T too_small = A.vectorD().tail(1)(0);
36  domain_error(function, name, too_small, msg_str.c_str(), ".");
37  }
38 }
39 
40 } // namespace math
41 } // namespace stan
42 #endif
const XML_Char * name
Definition: expat.h:151
void check_ldlt_factor(const char *function, const char *name, LDLT_factor< T, R, C > &A)
vector_t vectorD() const
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
static const double A
Definition: Units.h:82
double T
Definition: Xdiff_gwt.C:5
enum BeamMode string