Stan Math Library  2.20.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 
7 #include <string>
8 
9 namespace stan {
10 namespace math {
11 
12 namespace internal {
13 template <typename T_y, typename T_low, bool is_vec>
15  static void check(const char* function, const char* name, const T_y& y,
16  const T_low& low) {
17  scalar_seq_view<T_low> low_vec(low);
18  for (size_t n = 0; n < stan::length(low); n++) {
19  if (!(y >= low_vec[n])) {
20  std::stringstream msg;
21  msg << ", but must be greater than or equal to ";
22  msg << low_vec[n];
23  std::string msg_str(msg.str());
24  domain_error(function, name, y, "is ", msg_str.c_str());
25  }
26  }
27  }
28 };
29 
30 template <typename T_y, typename T_low>
31 struct greater_or_equal<T_y, T_low, true> {
32  static void check(const char* function, const char* name, const T_y& y,
33  const T_low& low) {
34  scalar_seq_view<T_low> low_vec(low);
35  for (size_t n = 0; n < stan::length(y); n++) {
36  if (!(stan::get(y, n) >= low_vec[n])) {
37  std::stringstream msg;
38  msg << ", but must be greater than or equal to ";
39  msg << low_vec[n];
40  std::string msg_str(msg.str());
41  domain_error_vec(function, name, y, n, "is ", msg_str.c_str());
42  }
43  }
44  }
45 };
46 } // namespace internal
47 
61 template <typename T_y, typename T_low>
62 inline void check_greater_or_equal(const char* function, const char* name,
63  const T_y& y, const T_low& low) {
65  function, name, y, low);
66 }
67 } // namespace math
68 } // namespace stan
69 #endif
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
size_t length(const std::vector< T > &x)
Returns the length of the provided std::vector.
Definition: length.hpp:16
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)
Returns the n-th element of the provided std::vector.
Definition: get.hpp:16
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.
static void check(const char *function, const char *name, const T_y &y, const T_low &low)
static void check(const char *function, const char *name, const T_y &y, const T_low &low)

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