Stan Math Library  2.20.0
reverse mode automatic differentiation
check_matching_dims.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_MATCHING_DIMS_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_MATCHING_DIMS_HPP
3 
9 #include <sstream>
10 #include <string>
11 
12 namespace stan {
13 namespace math {
14 
32 template <typename T1, typename T2, int R1, int C1, int R2, int C2>
33 inline void check_matching_dims(const char* function, const char* name1,
34  const Eigen::Matrix<T1, R1, C1>& y1,
35  const char* name2,
36  const Eigen::Matrix<T2, R2, C2>& y2) {
37  check_size_match(function, "Rows of ", name1, y1.rows(), "rows of ", name2,
38  y2.rows());
39  check_size_match(function, "Columns of ", name1, y1.cols(), "columns of ",
40  name2, y2.cols());
41 }
42 
63 template <bool check_compile, typename T1, typename T2, int R1, int C1, int R2,
64  int C2>
65 inline void check_matching_dims(const char* function, const char* name1,
66  const Eigen::Matrix<T1, R1, C1>& y1,
67  const char* name2,
68  const Eigen::Matrix<T2, R2, C2>& y2) {
69  if (check_compile && (R1 != R2 || C1 != C2)) {
70  std::ostringstream msg;
71  msg << "Static rows and cols of " << name1 << " and " << name2
72  << " must match in size.";
73  std::string msg_str(msg.str());
74  invalid_argument(function, msg_str.c_str(), "", "");
75  }
76  check_matching_dims(function, name1, y1, name2, y2);
77 }
78 
79 } // namespace math
80 } // namespace stan
81 #endif
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
void check_matching_dims(const char *function, const char *name1, const matrix_cl &y1, const char *name2, const matrix_cl &y2)
Check if two matrix_cls have the same dimensions.
void invalid_argument(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw an invalid_argument exception with a consistently formatted message.

     [ Stan Home Page ] © 2011–2018, Stan Development Team.