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

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