check_lower_triangular.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_LOWER_TRIANGULAR_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_LOWER_TRIANGULAR_HPP
3 
7 #include <sstream>
8 #include <string>
9 
10 namespace stan {
11 namespace math {
12 /**
13  * Check if the specified matrix is lower
14  * triangular.
15  *
16  * A matrix x is not lower triangular if there is a non-zero entry
17  * x[m, n] with m &lt; n. This function only inspects the upper
18  * triangular portion of the matrix, not including the diagonal.
19  *
20  * @tparam T Type of scalar of the matrix
21  *
22  * @param function Function name (for error messages)
23  * @param name Variable name (for error messages)
24  * @param y Matrix to test
25  *
26  * @throw <code>std::domain_error</code> if the matrix is not
27  * lower triangular or if any element in the upper triangular
28  * portion is NaN
29  */
30 template <typename T_y>
32  const char* function, const char* name,
33  const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y) {
34  for (int n = 1; n < y.cols(); ++n) {
35  for (int m = 0; m < n && m < y.rows(); ++m) {
36  if (y(m, n) != 0) {
37  std::stringstream msg;
38  msg << "is not lower triangular;"
39  << " " << name << "[" << stan::error_index::value + m << ","
40  << stan::error_index::value + n << "]=";
41  std::string msg_str(msg.str());
42  domain_error(function, name, y(m, n), msg_str.c_str());
43  }
44  }
45  }
46 }
47 
48 } // namespace math
49 } // namespace stan
50 #endif
const XML_Char * name
Definition: expat.h:151
void check_lower_triangular(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
enum BeamMode string