Stan Math Library  2.20.0
reverse mode automatic differentiation
check_size_match.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_SIZE_MATCH_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_CHECK_SIZE_MATCH_HPP
3 
6 #include <sstream>
7 #include <string>
8 
9 namespace stan {
10 namespace math {
11 
23 template <typename T_size1, typename T_size2>
24 inline void check_size_match(const char* function, const char* name_i,
25  T_size1 i, const char* name_j, T_size2 j) {
26  if (i == static_cast<T_size1>(j))
27  return;
28 
29  std::ostringstream msg;
30  msg << ") and " << name_j << " (" << j << ") must match in size";
31  std::string msg_str(msg.str());
32  invalid_argument(function, name_i, i, "(", msg_str.c_str());
33 }
34 
48 template <typename T_size1, typename T_size2>
49 inline void check_size_match(const char* function, const char* expr_i,
50  const char* name_i, T_size1 i, const char* expr_j,
51  const char* name_j, T_size2 j) {
52  if (i == static_cast<T_size1>(j))
53  return;
54  std::ostringstream updated_name;
55  updated_name << expr_i << name_i;
56  std::string updated_name_str(updated_name.str());
57  std::ostringstream msg;
58  msg << ") and " << expr_j << name_j << " (" << j << ") must match in size";
59  std::string msg_str(msg.str());
60  invalid_argument(function, updated_name_str.c_str(), i, "(", msg_str.c_str());
61 }
62 
63 } // namespace math
64 } // namespace stan
65 #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 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.