Automatic Differentiation
 
Loading...
Searching...
No Matches
check_size_match.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_ERR_CHECK_SIZE_MATCH_HPP
2#define STAN_MATH_PRIM_ERR_CHECK_SIZE_MATCH_HPP
3
6#include <sstream>
7#include <string>
8
9namespace stan {
10namespace math {
11
23template <typename T_size1, typename T_size2>
24inline 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 [&]() STAN_COLD_PATH {
28 std::ostringstream msg;
29 msg << ") and " << name_j << " (" << j << ") must match in size";
30 std::string msg_str(msg.str());
31 invalid_argument(function, name_i, i, "(", msg_str.c_str());
32 }();
33 }
34}
35
49template <typename T_size1, typename T_size2>
50inline void check_size_match(const char* function, const char* expr_i,
51 const char* name_i, T_size1 i, const char* expr_j,
52 const char* name_j, T_size2 j) {
53 if (i != static_cast<T_size1>(j)) {
54 [&]() STAN_COLD_PATH {
55 std::ostringstream updated_name;
56 updated_name << expr_i << name_i;
57 std::string updated_name_str(updated_name.str());
58 std::ostringstream msg;
59 msg << ") and " << expr_j << name_j << " (" << j
60 << ") must match in size";
61 std::string msg_str(msg.str());
62 invalid_argument(function, updated_name_str.c_str(), i, "(",
63 msg_str.c_str());
64 }();
65 }
66}
67
68} // namespace math
69} // namespace stan
70#endif
#define STAN_COLD_PATH
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.
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.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...