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

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