Stan Math Library  2.20.0
reverse mode automatic differentiation
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 
22 template <typename T>
23 inline void check_consistent_size(const char* function, const char* name,
24  const T& x, size_t expected_size) {
26  || (is_vector<T>::value && expected_size == stan::size_of(x)))
27  return;
28 
29  std::stringstream msg;
30  msg << ", expecting dimension = " << expected_size
31  << "; a function was called with arguments of different "
32  << "scalar, array, vector, or matrix types, and they were not "
33  << "consistently sized; all arguments must be scalars or "
34  << "multidimensional values of the same shape.";
35  std::string msg_str(msg.str());
36 
37  invalid_argument(function, name, stan::size_of(x),
38  "has dimension = ", msg_str.c_str());
39 }
40 
41 } // namespace math
42 } // namespace stan
43 #endif
void check_consistent_size(const char *function, const char *name, const T &x, size_t expected_size)
Check if the dimension of x is consistent, which is defined to be expected_size if x is a vector or 1...
size_t size_of(const T &x)
Returns the size of the provided vector or the constant 1 if the input argument is not a vector...
Definition: size_of.hpp:27
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.