Stan Math Library  2.14.0
reverse mode automatic differentiation
check_less_or_equal.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_LESS_OR_EQUAL_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_CHECK_LESS_OR_EQUAL_HPP
3 
10 #include <string>
11 
12 namespace stan {
13  namespace math {
14 
15  namespace {
16  template <typename T_y, typename T_high, bool is_vec>
17  struct less_or_equal {
18  static void check(const char* function,
19  const char* name,
20  const T_y& y,
21  const T_high& high) {
22  using stan::length;
23  VectorView<const T_high> high_vec(high);
24  for (size_t n = 0; n < length(high); n++) {
25  if (!(y <= high_vec[n])) {
26  std::stringstream msg;
27  msg << ", but must be less than or equal to ";
28  msg << high_vec[n];
29  std::string msg_str(msg.str());
30  domain_error(function, name, y,
31  "is ", msg_str.c_str());
32  }
33  }
34  }
35  };
36 
37  template <typename T_y, typename T_high>
38  struct less_or_equal<T_y, T_high, true> {
39  static void check(const char* function,
40  const char* name,
41  const T_y& y,
42  const T_high& high) {
43  using stan::length;
44  VectorView<const T_high> high_vec(high);
45  for (size_t n = 0; n < length(y); n++) {
46  if (!(stan::get(y, n) <= high_vec[n])) {
47  std::stringstream msg;
48  msg << ", but must be less than or equal to ";
49  msg << high_vec[n];
50  std::string msg_str(msg.str());
51  domain_error_vec(function, name, y, n,
52  "is ", msg_str.c_str());
53  }
54  }
55  }
56  };
57  }
58 
77  template <typename T_y, typename T_high>
78  inline void check_less_or_equal(const char* function,
79  const char* name,
80  const T_y& y,
81  const T_high& high) {
82  less_or_equal<T_y, T_high, is_vector_like<T_y>::value>
83  ::check(function, name, y, high);
84  }
85  }
86 }
87 #endif
void check_less_or_equal(const char *function, const char *name, const T_y &y, const T_high &high)
Check if y is less or equal to high.
size_t length(const std::vector< T > &x)
Definition: length.hpp:10
void domain_error_vec(const char *function, const char *name, const T &y, size_t i, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
T get(const std::vector< T > &x, size_t n)
Definition: get.hpp:10
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.

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