Stan Math Library  2.15.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, typename T_low, bool is_vec>
16  struct greater_or_equal {
17  static void check(const char* function,
18  const char* name,
19  const T_y& y,
20  const T_low& low) {
21  using stan::length;
22  scalar_seq_view<T_low> low_vec(low);
23  for (size_t n = 0; n < length(low); n++) {
24  if (!(y >= low_vec[n])) {
25  std::stringstream msg;
26  msg << ", but must be greater than or equal to ";
27  msg << low_vec[n];
28  std::string msg_str(msg.str());
29  domain_error(function, name, y,
30  "is ", msg_str.c_str());
31  }
32  }
33  }
34  };
35 
36  template <typename T_y, typename T_low>
37  struct greater_or_equal<T_y, T_low, true> {
38  static void check(const char* function,
39  const char* name,
40  const T_y& y,
41  const T_low& low) {
42  using stan::length;
43  using stan::get;
44  scalar_seq_view<T_low> low_vec(low);
45  for (size_t n = 0; n < length(y); n++) {
46  if (!(get(y, n) >= low_vec[n])) {
47  std::stringstream msg;
48  msg << ", but must be greater than or equal to ";
49  msg << low_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_low>
78  inline void check_greater_or_equal(const char* function,
79  const char* name,
80  const T_y& y,
81  const T_low& low) {
82  greater_or_equal<T_y, T_low, is_vector_like<T_y>::value>
83  ::check(function, name, y, low);
84  }
85  }
86 }
87 #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, size_t i, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
void check_greater_or_equal(const char *function, const char *name, const T_y &y, const T_low &low)
Check if y is greater or equal than low.
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.