Automatic Differentiation
 
Loading...
Searching...
No Matches
check_cholesky_factor.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_ERR_CHECK_CHOLESKY_FACTOR_HPP
2#define STAN_MATH_PRIM_ERR_CHECK_CHOLESKY_FACTOR_HPP
3
12
13namespace stan {
14namespace math {
15
32template <typename Mat, require_matrix_t<Mat>* = nullptr>
33inline void check_cholesky_factor(const char* function, const char* name,
34 const Mat& y) {
35 check_less_or_equal(function, "columns and rows of Cholesky factor", y.cols(),
36 y.rows());
37 check_positive(function, "columns of Cholesky factor", y.cols());
38 auto&& y_ref = to_ref(value_of_rec(y));
39 check_lower_triangular(function, name, y_ref);
40 check_positive(function, name, y_ref.diagonal());
41}
42
60template <typename StdVec, require_std_vector_t<StdVec>* = nullptr>
61void check_cholesky_factor(const char* function, const char* name,
62 const StdVec& y) {
63 for (size_t i = 0; i < y.size(); ++i) {
64 check_cholesky_factor(function, internal::make_iter_name(name, i).c_str(),
65 y[i]);
66 }
67}
68
69} // namespace math
70} // namespace stan
71#endif
auto make_iter_name(const char *name)
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
void check_less_or_equal(const char *function, const char *name, const T_y &y, const T_high &high, Idxs... idxs)
Throw an exception if y is not less than high.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
void check_cholesky_factor(const char *function, const char *name, const Mat &y)
Throw an exception if the specified matrix is not a valid Cholesky factor.
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
void check_lower_triangular(const char *function, const char *name, const T_y &y)
Check if the specified matrix is lower triangular.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...