Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations 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 
6 #include <boost/math/special_functions/fpclassify.hpp>
7 #include <stan/meta/traits.hpp>
8 
9 namespace stan {
10  namespace math {
11 
12  namespace {
13  template <typename T_y, typename T_result, bool is_vec>
14  struct not_nan {
15  static bool check(const char* function,
16  const T_y& y,
17  const char* name,
18  T_result* result) {
19  if ((boost::math::isnan)(y))
20  return dom_err(function,y,name,
21  " is %1%, but must not be nan!","",
22  result);
23  return true;
24  }
25  };
26 
27  template <typename T_y, typename T_result>
28  struct not_nan<T_y, T_result, true> {
29  static bool check(const char* function,
30  const T_y& y,
31  const char* name,
32  T_result* result) {
33  // using stan::length;
34  for (size_t n = 0; n < stan::length(y); n++) {
35  if ((boost::math::isnan)(stan::get(y,n)))
36  return dom_err_vec(n,function,y,name,
37  " is %1%, but must not be nan!","",
38  result);
39  }
40  return true;
41  }
42  };
43  }
44 
55  template <typename T_y, typename T_result>
56  inline bool check_not_nan(const char* function,
57  const T_y& y,
58  const char* name,
59  T_result* result) {
60  return not_nan<T_y,T_result,is_vector_like<T_y>::value>
61  ::check(function, y, name, result);
62  }
63 
64  }
65 }
66 #endif
bool isnan(const stan::agrad::var &v)
Checks if the given number is NaN.
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
bool check_not_nan(const char *function, const T_y &y, const char *name, T_result *result)
Checks if the variable y is nan.
T get(const T &x, size_t n)
Definition: traits.hpp:143

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