Stan Math Library  2.12.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 bool 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  return true;
35  }
36  };
37 
38  template <typename T_y, typename T_high>
39  struct less_or_equal<T_y, T_high, true> {
40  static bool check(const char* function,
41  const char* name,
42  const T_y& y,
43  const T_high& high) {
44  using stan::length;
45  VectorView<const T_high> high_vec(high);
46  for (size_t n = 0; n < length(y); n++) {
47  if (!(stan::get(y, n) <= high_vec[n])) {
48  std::stringstream msg;
49  msg << ", but must be less than or equal to ";
50  msg << high_vec[n];
51  std::string msg_str(msg.str());
52  domain_error_vec(function, name, y, n,
53  "is ", msg_str.c_str());
54  }
55  }
56  return true;
57  }
58  };
59  }
60 
80  template <typename T_y, typename T_high>
81  inline bool check_less_or_equal(const char* function,
82  const char* name,
83  const T_y& y,
84  const T_high& high) {
85  return less_or_equal<T_y, T_high, is_vector_like<T_y>::value>
86  ::check(function, name, y, high);
87  }
88  }
89 }
90 #endif
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, const 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.
bool check_less_or_equal(const char *function, const char *name, const T_y &y, const T_high &high)
Return true if y is less or equal to high.

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