Stan Math Library  2.20.0
reverse mode automatic differentiation
check_consistent_size_mvt.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_CONSISTENT_SIZE_MVT_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_CHECK_CONSISTENT_SIZE_MVT_HPP
3 
6 #include <sstream>
7 #include <string>
8 #include <type_traits>
9 
10 namespace stan {
11 namespace math {
12 
24 template <typename T>
25 inline void check_consistent_size_mvt(const char* function, const char* name,
26  const T& x, size_t expected_size) {
27  size_t size_x = 0;
28 
29  if (length(x) == 0) {
30  size_x = 0;
31  if (expected_size == 0)
32  return;
33  } else {
34  size_t size_x = stan::length_mvt(x);
35  bool x_contains_vectors = is_vector<
36  typename std::remove_reference<decltype(x[0])>::type>::value;
37 
38  if (!x_contains_vectors)
39  return;
40  else if (expected_size == size_x)
41  return;
42  }
43 
44  std::stringstream msg;
45  msg << ", expecting dimension = " << expected_size
46  << "; a function was called with arguments of different "
47  << "scalar, array, vector, or matrix types, and they were not "
48  << "consistently sized; all arguments must be scalars or "
49  << "multidimensional values of the same shape.";
50  std::string msg_str(msg.str());
51 
52  invalid_argument(function, name, size_x, "has dimension = ", msg_str.c_str());
53 }
54 
55 } // namespace math
56 } // namespace stan
57 #endif
size_t length(const std::vector< T > &x)
Returns the length of the provided std::vector.
Definition: length.hpp:16
void check_consistent_size_mvt(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 of v...
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.
size_t length_mvt(const Eigen::Matrix< T, R, C > &)
Definition: length_mvt.hpp:12

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