check_row_index.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_ROW_INDEX_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_ROW_INDEX_HPP
3 
6 #include <sstream>
7 #include <string>
8 
9 namespace stan {
10 namespace math {
11 
12 /**
13  * Check if the specified index is a valid row of the matrix
14  *
15  * This check is 1-indexed by default. This behavior can be changed
16  * by setting <code>stan::error_index::value</code>.
17  *
18  * @tparam T Scalar type
19  * @tparam R Compile time rows
20  * @tparam C Compile time columns
21  *
22  * @param function Function name (for error messages)
23  * @param name Variable name (for error messages)
24  * @param y Matrix to test
25  * @param i is index
26  *
27  * @throw <code>std::out_of_range</code> if the index is out of range.
28  */
29 template <typename T_y, int R, int C>
30 inline void check_row_index(const char* function, const char* name,
31  const Eigen::Matrix<T_y, R, C>& y, size_t i) {
33  && i < static_cast<size_t>(y.rows()) + stan::error_index::value)
34  return;
35 
36  std::stringstream msg;
37  msg << " for rows of " << name;
38  std::string msg_str(msg.str());
39  out_of_range(function, y.rows(), i, msg_str.c_str());
40 }
41 
42 } // namespace math
43 } // namespace stan
44 #endif
const XML_Char * name
Definition: expat.h:151
void check_row_index(const char *function, const char *name, const Eigen::Matrix< T_y, R, C > &y, size_t i)
void out_of_range(const char *function, int max, int index, const char *msg1="", const char *msg2="")
enum BeamMode string