check_consistent_size.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_CONSISTENT_SIZE_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_CHECK_CONSISTENT_SIZE_HPP
3 
6 #include <sstream>
7 #include <string>
8 
9 namespace stan {
10 namespace math {
11 
12 /**
13  * Check if the dimension of x is consistent, which
14  * is defined to be <code>expected_size</code> if x is a vector or 1 if x
15  * is not a vector.
16  *
17  * @tparam T Type of value
18  *
19  * @param function Function name (for error messages)
20  * @param name Variable name (for error messages)
21  * @param x Variable to check for consistent size
22  * @param expected_size Expected size if x is a vector
23  *
24  * @throw <code>invalid_argument</code> if the size is inconsistent
25  */
26 template <typename T>
27 inline void check_consistent_size(const char* function, const char* name,
28  const T& x, size_t expected_size) {
30  return;
31  if (is_vector<T>::value && expected_size == stan::size_of(x))
32  return;
33 
34  std::stringstream msg;
35  msg << ", expecting dimension = " << expected_size
36  << "; a function was called with arguments of different "
37  << "scalar, array, vector, or matrix types, and they were not "
38  << "consistently sized; all arguments must be scalars or "
39  << "multidimensional values of the same shape.";
40  std::string msg_str(msg.str());
41 
42  invalid_argument(function, name, stan::size_of(x),
43  "has dimension = ", msg_str.c_str());
44 }
45 
46 } // namespace math
47 } // namespace stan
48 #endif
const XML_Char * name
Definition: expat.h:151
void check_consistent_size(const char *function, const char *name, const T &x, size_t expected_size)
size_t size_of(const T &x)
Definition: size_of.hpp:20
void invalid_argument(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
double T
Definition: Xdiff_gwt.C:5
enum BeamMode string