Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
check_consistent_size.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__ERROR_HANDLING__CHECK_CONSISTENT_SIZE_HPP
2 #define STAN__MATH__ERROR_HANDLING__CHECK_CONSISTENT_SIZE_HPP
3 
4 #include <sstream>
6 #include <stan/meta/traits.hpp>
7 
8 namespace stan {
9  namespace math {
10 
11  // NOTE: this will not throw if nan is passed in.
12  template <typename T, typename T_result>
13  inline bool check_consistent_size(size_t max_size,
14  const char* function,
15  const T& x,
16  const char* name,
17  T_result* result) {
18  size_t x_size = stan::size_of(x);
19  if (is_vector<T>::value && x_size == max_size)
20  return true;
21  if (!is_vector<T>::value && x_size == 1)
22  return true;
23 
24  std::stringstream msg;
25  msg << " dimension=%1%, expecting dimension of either 1 or "
26  << "max_size=" << max_size
27  << "; a vectorized function was called with arguments of different "
28  << "scalar, array, vector, or matrix types, and they were not "
29  << "consistently sized; all arguments must be scalars or "
30  << "multidimensional values of the same shape.";
31 
32  std::string tmp(msg.str());
33 
34  return dom_err(function,x_size,name,
35  tmp.c_str(), "",
36  result);
37  }
38 
39  }
40 }
41 #endif
bool dom_err(const char *function, const T &y, const char *name, const char *error_msg, const T_msg error_msg2, T_result *result)
Definition: dom_err.hpp:36
bool check_consistent_size(size_t max_size, const char *function, const T &x, const char *name, T_result *result)
size_t size_of(const T &x)
Definition: traits.hpp:186
size_t max_size(const T1 &x1, const T2 &x2)
Definition: traits.hpp:191

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