Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
check_less_or_equal.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__ERROR_HANDLING_CHECK_LESS_OR_EQUAL_HPP
2 #define STAN__MATH__ERROR_HANDLING_CHECK_LESS_OR_EQUAL_HPP
3 
6 
7 namespace stan {
8  namespace math {
9 
10  namespace {
11  template <typename T_y, typename T_high, typename T_result, bool is_vec>
12  struct less_or_equal {
13  static bool check(const char* function,
14  const T_y& y,
15  const T_high& high,
16  const char* name,
17  T_result* result) {
18  using stan::length;
19  VectorView<const T_high> high_vec(high);
20  for (size_t n = 0; n < length(high); n++) {
21  if (!(y <= high_vec[n]))
22  return dom_err(function,y,name,
23  " is %1%, but must be less than or equal to ",
24  high_vec[n],result);
25  }
26  return true;
27  }
28  };
29 
30  template <typename T_y, typename T_high, typename T_result>
31  struct less_or_equal<T_y, T_high, T_result, true> {
32  static bool check(const char* function,
33  const T_y& y,
34  const T_high& high,
35  const char* name,
36  T_result* result) {
37  using stan::length;
38  VectorView<const T_high> high_vec(high);
39  for (size_t n = 0; n < length(y); n++) {
40  if (!(stan::get(y,n) <= high_vec[n]))
41  return dom_err_vec(n,function,y,name,
42  " is %1%, but must be less than or equal to ",
43  high_vec[n],result);
44  }
45  return true;
46  }
47  };
48  }
49 
50  // throws if any element of y or high is nan
51  template <typename T_y, typename T_high, typename T_result>
52  inline bool check_less_or_equal(const char* function,
53  const T_y& y,
54  const T_high& high,
55  const char* name,
56  T_result* result) {
57  return less_or_equal<T_y,T_high,T_result,is_vector_like<T_y>::value>
58  ::check(function,y,high,name,result);
59  }
60 
61  }
62 }
63 #endif
bool dom_err(const char *function, const T &y, const char *name, const char *error_msg, const T_msg error_msg2, T_result *result)
Definition: dom_err.hpp:36
size_t length(const T &)
Definition: traits.hpp:159
bool dom_err_vec(const size_t i, const char *function, const T &y, const char *name, const char *error_msg, const T_msg error_msg2, T_result *result)
Definition: dom_err_vec.hpp:33
bool check_less_or_equal(const char *function, const T_y &y, const T_high &high, const char *name, T_result *result)
T get(const T &x, size_t n)
Definition: traits.hpp:143

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