Automatic Differentiation
 
Loading...
Searching...
No Matches
check_lower_triangular.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_ERR_CHECK_LOWER_TRIANGULAR_HPP
2#define STAN_MATH_PRIM_ERR_CHECK_LOWER_TRIANGULAR_HPP
3
7#include <sstream>
8#include <string>
9
10namespace stan {
11namespace math {
12
26template <typename T_y, require_eigen_t<T_y>* = nullptr>
27inline void check_lower_triangular(const char* function, const char* name,
28 const T_y& y) {
29 const auto& y_ref = to_ref(y);
30 for (int n = 1; n < y.cols(); ++n) {
31 for (int m = 0; m < n && m < y.rows(); ++m) {
32 if (y_ref(m, n) != 0) {
33 std::stringstream msg;
34 msg << "is not lower triangular;"
35 << " " << name << "[" << stan::error_index::value + m << ","
36 << stan::error_index::value + n << "]=";
37 std::string msg_str(msg.str());
38 throw_domain_error(function, name, y_ref(m, n), msg_str.c_str());
39 }
40 }
41 }
42}
43
44} // namespace math
45} // namespace stan
46#endif
void throw_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.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
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 ...