Stan Math Library  2.15.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 
4 #include <boost/type_traits/common_type.hpp>
7 #include <sstream>
8 #include <string>
9 
10 namespace stan {
11  namespace math {
12 
28  template <typename T_size1, typename T_size2>
29  inline void check_size_match(const char* function,
30  const char* name_i,
31  T_size1 i,
32  const char* name_j,
33  T_size2 j) {
34  if (likely(i == static_cast<T_size1>(j)))
35  return;
36 
37  std::ostringstream msg;
38  msg << ") and "
39  << name_j << " (" << j << ") must match in size";
40  std::string msg_str(msg.str());
41  invalid_argument(function, name_i, i,
42  "(", msg_str.c_str());
43  }
44 
62  template <typename T_size1, typename T_size2>
63  inline void check_size_match(const char* function,
64  const char* expr_i,
65  const char* name_i,
66  T_size1 i,
67  const char* expr_j,
68  const char* name_j,
69  T_size2 j) {
70  if (likely(i == static_cast<T_size1>(j)))
71  return;
72  std::ostringstream updated_name;
73  updated_name << expr_i << name_i;
74  std::string updated_name_str(updated_name.str());
75  std::ostringstream msg;
76  msg << ") and "
77  << expr_j << name_j
78  << " (" << j << ") must match in size";
79  std::string msg_str(msg.str());
80  invalid_argument(function, updated_name_str.c_str(), i,
81  "(", msg_str.c_str());
82  }
83 
84  }
85 }
86 #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.
#define likely(x)
Definition: likely.hpp:8

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