Stan Math Library  2.20.0
reverse mode automatic differentiation
check_less.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_LESS_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_CHECK_LESS_HPP
3 
7 #include <functional>
8 #include <string>
9 
10 namespace stan {
11 namespace math {
12 
13 namespace internal {
14 template <typename T_y, typename T_high, bool is_vec>
15 struct less {
16  static void check(const char* function, const char* name, const T_y& y,
17  const T_high& high) {
18  scalar_seq_view<T_high> high_vec(high);
19  for (size_t n = 0; n < stan::length(high); n++) {
20  if (!(y < high_vec[n])) {
21  std::stringstream msg;
22  msg << ", but must be less than ";
23  msg << high_vec[n];
24  std::string msg_str(msg.str());
25  domain_error(function, name, y, "is ", msg_str.c_str());
26  }
27  }
28  }
29 };
30 
31 template <typename T_y, typename T_high>
32 struct less<T_y, T_high, true> {
33  static void check(const char* function, const char* name, const T_y& y,
34  const T_high& high) {
35  scalar_seq_view<T_high> high_vec(high);
36  for (size_t n = 0; n < stan::length(y); n++) {
37  if (!(stan::get(y, n) < high_vec[n])) {
38  std::stringstream msg;
39  msg << ", but must be less than ";
40  msg << high_vec[n];
41  std::string msg_str(msg.str());
42  domain_error_vec(function, name, y, n, "is ", msg_str.c_str());
43  }
44  }
45  }
46 };
47 } // namespace internal
48 
62 template <typename T_y, typename T_high>
63 inline void check_less(const char* function, const char* name, const T_y& y,
64  const T_high& high) {
66  y, high);
67 }
68 } // namespace math
69 } // namespace stan
70 #endif
static void check(const char *function, const char *name, const T_y &y, const T_high &high)
Definition: check_less.hpp:16
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.
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_high &high)
Definition: check_less.hpp:33
void check_less(const char *function, const char *name, const T_y &y, const T_high &high)
Check if y is strictly less than high.
Definition: check_less.hpp:63

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