Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
check_not_nan.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__ERROR_HANDLING__CHECK_NOT_NAN_HPP__
2 #define __STAN__MATH__ERROR_HANDLING__CHECK_NOT_NAN_HPP__
3 
7 
8 namespace stan {
9  namespace math {
10 
11  namespace {
12  template <typename T_y,
13  typename T_result,
14  class Policy,
15  bool is_vec>
16  struct not_nan {
17  static bool check(const char* function,
18  const T_y& y,
19  const char* name,
20  T_result* result,
21  const Policy&) {
22  if ((boost::math::isnan)(y))
23  return dom_err(function,y,name,
24  " is %1%, but must not be nan!","",
25  result,Policy());
26  return true;
27  }
28  };
29 
30  template <typename T_y,
31  typename T_result,
32  class Policy>
33  struct not_nan<T_y, T_result, Policy, true> {
34  static bool check(const char* function,
35  const T_y& y,
36  const char* name,
37  T_result* result,
38  const Policy&) {
39  // using stan::length;
40  for (size_t n = 0; n < stan::length(y); n++) {
41  if ((boost::math::isnan)(stan::get(y,n)))
42  return dom_err_vec(n,function,y,name,
43  " is %1%, but must not be nan!","",
44  result,Policy());
45  }
46  return true;
47  }
48  };
49  }
50 
62  template <typename T_y,
63  typename T_result,
64  class Policy>
65  inline bool check_not_nan(const char* function,
66  const T_y& y,
67  const char* name,
68  T_result* result,
69  const Policy&) {
70  return not_nan<T_y,T_result,Policy,
72  ::check(function, y, name, result, Policy());
73  }
74 
86  template <typename T_y,
87  typename T_result>
88  inline bool check_not_nan(const char* function,
89  const T_y& y,
90  const char* name,
91  T_result* result = 0) {
92  return check_not_nan(function,y,name,result,default_policy());
93  }
94 
95  // need this sig to infer types for result from type of y
96  template <typename T>
97  inline bool check_not_nan(const char* function,
98  const T& y,
99  const char* name) {
100  return check_not_nan<T, typename scalar_type<T>::type *>
101  (function,y,name,0,default_policy());
102  }
103 
104  }
105 }
106 #endif

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