Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs 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 
7 
8 namespace stan {
9  namespace math {
10 
11  namespace {
12  template <typename T_y,
13  typename T_high,
14  typename T_result,
15  class Policy,
16  bool is_vec>
17  struct less_or_equal {
18  static bool check(const char* function,
19  const T_y& y,
20  const T_high& high,
21  const char* name,
22  T_result* result,
23  const Policy&) {
24  using stan::length;
25  VectorView<const T_high> high_vec(high);
26  for (size_t n = 0; n < length(high); n++) {
27  if (!(y <= high_vec[n]))
28  return dom_err(function,y,name,
29  " is %1%, but must be less than or equal to ",
30  high_vec[n],result,Policy());
31  }
32  return true;
33  }
34  };
35 
36  template <typename T_y,
37  typename T_high,
38  typename T_result,
39  class Policy>
40  struct less_or_equal<T_y, T_high, T_result, Policy, true> {
41  static bool check(const char* function,
42  const T_y& y,
43  const T_high& high,
44  const char* name,
45  T_result* result,
46  const Policy&) {
47  using stan::length;
48  VectorView<const T_high> high_vec(high);
49  for (size_t n = 0; n < length(y); n++) {
50  if (!(stan::get(y,n) <= high_vec[n]))
51  return dom_err_vec(n,function,y,name,
52  " is %1%, but must be less than or equal to ",
53  high_vec[n],result,Policy());
54  }
55  return true;
56  }
57  };
58  }
59  template <typename T_y, typename T_high, typename T_result, class Policy>
60  inline bool check_less_or_equal(const char* function,
61  const T_y& y,
62  const T_high& high,
63  const char* name,
64  T_result* result,
65  const Policy&) {
66  return less_or_equal<T_y,T_high,T_result,Policy,
68  ::check(function,y,high,name,result,Policy());
69  }
70  template <typename T_y, typename T_high, typename T_result>
71  inline bool check_less_or_equal(const char* function,
72  const T_y& y,
73  const T_high& high,
74  const char* name,
75  T_result* result) {
76  return check_less_or_equal(function,y,high,name,result,default_policy());
77  }
78  template <typename T_y, typename T_high>
79  inline bool check_less_or_equal(const char* function,
80  const T_y& y,
81  const T_high& high,
82  const char* name) {
83  return check_less_or_equal<T_y,T_high,typename scalar_type<T_y>::type *>
84  (function,y,high,name,0,default_policy());
85  }
86 
87  }
88 }
89 #endif

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