| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/scal/err/invalid_argument.hpp>
5 #include <stan/math/prim/scal/meta/size_of.hpp>
6 #include <sstream>
7 #include <string>
8
9 namespace stan {
10 namespace math {
11
28 template <typename T>
29 inline bool check_consistent_size(const char* function,
30 const char* name,
31 const T& x,
32 size_t expected_size) {
33 if (!is_vector<T>::value)
34 return true;
35 if (is_vector<T>::value && expected_size == stan::size_of(x))
36 return true;
37
38 std::stringstream msg;
39 msg << ", expecting dimension = "
40 << expected_size
41 << "; a function was called with arguments of different "
42 << "scalar, array, vector, or matrix types, and they were not "
43 << "consistently sized; all arguments must be scalars or "
44 << "multidimensional values of the same shape.";
45 std::string msg_str(msg.str());
46
47 invalid_argument(function, name, stan::size_of(x),
48 "has dimension = ",
49 msg_str.c_str());
50 return false;
51 }
52
53 }
54 }
55 #endif
stan
Definition: log_sum_exp.hpp:8
invalid_argument.hpp
size_of.hpp
stan::is_vector
Definition: is_vector.hpp:10
stan::math::check_consistent_size
bool check_consistent_size(const char *function, const char *name, const T &x, size_t expected_size)
Return true if the dimension of x is consistent, which is defined to be expected_size if x is a vecto...
Definition: check_consistent_size.hpp:29
stan::size_of
size_t size_of(const T &x)
Definition: size_of.hpp:24
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 Home Page ] © 2011–2016, Stan Development Team.