Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
check_less.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__ERROR_HANDLING__CHECK_LESS_HPP__
2 #define __STAN__MATH__ERROR_HANDLING__CHECK_LESS_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 {
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 ",
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<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 ",
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(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<T_y,T_high,T_result,Policy,is_vector_like<T_y>::value>
67  ::check(function,y,high,name,result,Policy());
68  }
69  template <typename T_y, typename T_high, typename T_result>
70  inline bool check_less(const char* function,
71  const T_y& y,
72  const T_high& high,
73  const char* name,
74  T_result* result) {
75  return check_less(function,y,high,name,result,default_policy());
76  }
77  template <typename T_y, typename T_high>
78  inline bool check_less(const char* function,
79  const T_y& y,
80  const T_high& high,
81  const char* name) {
82  return check_less<T_y,T_high,typename scalar_type<T_y>::type *>
83  (function,y,high,name,0,default_policy());
84  }
85 
86  }
87 }
88 #endif

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