Stan Math Library  2.8.0
reverse mode automatic differentiation
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
check_greater.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_GREATER_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_CHECK_GREATER_HPP
3 
9 #include <functional>
10 #include <string>
11 
12 namespace stan {
13  namespace math {
14 
15  namespace {
16  template <typename T_y,
17  typename T_low,
18  bool is_vec>
19  struct greater {
20  static bool check(const char* function,
21  const char* name,
22  const T_y& y,
23  const T_low& low) {
24  using stan::length;
25  VectorView<const T_low> low_vec(low);
26  for (size_t n = 0; n < length(low); n++) {
27  if (!(y > low_vec[n])) {
28  std::stringstream msg;
29  msg << ", but must be greater than ";
30  msg << low_vec[n];
31  std::string msg_str(msg.str());
32  domain_error(function, name, y,
33  "is ", msg_str.c_str());
34  }
35  }
36  return true;
37  }
38  };
39 
40  template <typename T_y,
41  typename T_low>
42  struct greater<T_y, T_low, true> {
43  static bool check(const char* function,
44  const char* name,
45  const T_y& y,
46  const T_low& low) {
47  using stan::length;
48  VectorView<const T_low> low_vec(low);
49  for (size_t n = 0; n < length(y); n++) {
50  if (!(stan::get(y, n) > low_vec[n])) {
51  std::stringstream msg;
52  msg << ", but must be greater than ";
53  msg << low_vec[n];
54  std::string msg_str(msg.str());
55  domain_error_vec(function, name, y, n,
56  "is ", msg_str.c_str());
57  }
58  }
59  return true;
60  }
61  };
62  }
63 
83  template <typename T_y, typename T_low>
84  inline bool check_greater(const char* function,
85  const char* name,
86  const T_y& y,
87  const T_low& low) {
88  return greater<T_y, T_low, is_vector_like<T_y>::value>
89  ::check(function, name, y, low);
90  }
91  }
92 }
93 #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, const 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)
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.
bool check_greater(const char *function, const char *name, const T_y &y, const T_low &low)
Return true if y is strictly greater than low.

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