Stan Math Library  2.11.0
reverse mode automatic differentiation
check_greater_or_equal.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_GREATER_OR_EQUAL_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_CHECK_GREATER_OR_EQUAL_HPP
3 
9 #include <string>
10 
11 namespace stan {
12  namespace math {
13 
14  namespace {
15  template <typename T_y,
16  typename T_low,
17  bool is_vec>
18  struct greater_or_equal {
19  static bool check(const char* function,
20  const char* name,
21  const T_y& y,
22  const T_low& low) {
23  using stan::length;
24  VectorView<const T_low> low_vec(low);
25  for (size_t n = 0; n < length(low); n++) {
26  if (!(y >= low_vec[n])) {
27  std::stringstream msg;
28  msg << ", but must be greater than or equal to ";
29  msg << low_vec[n];
30  std::string msg_str(msg.str());
31  domain_error(function, name, y,
32  "is ", msg_str.c_str());
33  }
34  }
35  return true;
36  }
37  };
38 
39  template <typename T_y,
40  typename T_low>
41  struct greater_or_equal<T_y, T_low, true> {
42  static bool check(const char* function,
43  const char* name,
44  const T_y& y,
45  const T_low& low) {
46  using stan::length;
47  using stan::get;
48  VectorView<const T_low> low_vec(low);
49  for (size_t n = 0; n < length(y); n++) {
50  if (!(get(y, n) >= low_vec[n])) {
51  std::stringstream msg;
52  msg << ", but must be greater than or equal to ";
53  msg << low_vec[n];
54  std::string msg_str(msg.str());
55  domain_error_vec(function, name, y, n,
56  "is ", msg_str.c_str());
57  }
58  }
59  return true;
60  }
61  };
62  }
63 
83  template <typename T_y, typename T_low>
84  inline bool check_greater_or_equal(const char* function,
85  const char* name,
86  const T_y& y,
87  const T_low& low) {
88  return greater_or_equal<T_y, T_low, is_vector_like<T_y>::value>
89  ::check(function, name, y, low);
90  }
91  }
92 }
93 #endif
bool check_greater_or_equal(const char *function, const char *name, const T_y &y, const T_low &low)
Return true if y is greater or equal than low.
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.

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