| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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>
5 #include <stan/math/prim/scal/err/invalid_argument.hpp>
6 #include <stan/math/prim/scal/meta/likely.hpp>
7 #include <sstream>
8 #include <string>
9
10 namespace stan {
11 namespace math {
12
29 template <typename T_size1, typename T_size2>
30 inline bool check_size_match(const char* function,
31 const char* name_i,
32 T_size1 i,
33 const char* name_j,
34 T_size2 j) {
35 if (likely(i == static_cast<T_size1>(j)))
36 return true;
37
38 std::ostringstream msg;
39 msg << ") and "
40 << name_j << " (" << j << ") must match in size";
41 std::string msg_str(msg.str());
42 invalid_argument(function, name_i, i,
43 "(", msg_str.c_str());
44 return false;
45 }
46
47
66 template <typename T_size1, typename T_size2>
67 inline bool check_size_match(const char* function,
68 const char* expr_i,
69 const char* name_i,
70 T_size1 i,
71 const char* expr_j,
72 const char* name_j,
73 T_size2 j) {
74 if (likely(i == static_cast<T_size1>(j)))
75 return true;
76 std::ostringstream updated_name;
77 updated_name << expr_i << name_i;
78 std::string updated_name_str(updated_name.str());
79 std::ostringstream msg;
80 msg << ") and "
81 << expr_j << name_j
82 << " (" << j << ") must match in size";
83 std::string msg_str(msg.str());
84 invalid_argument(function, updated_name_str.c_str(), i,
85 "(", msg_str.c_str());
86 return false;
87 }
88
89 }
90 }
91 #endif
stan
Definition: log_sum_exp.hpp:8
invalid_argument.hpp
likely
#define likely(x)
Definition: likely.hpp:8
stan::math::invalid_argument
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.
Definition: invalid_argument.hpp:31
stan::math::check_size_match
bool check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Return true if the provided sizes match.
Definition: check_size_match.hpp:30
likely.hpp

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