Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
check_finite.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__ERROR_HANDLING_CHECK_FINITE_HPP
2 #define STAN__MATH__ERROR_HANDLING_CHECK_FINITE_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,
14  typename T_result,
15  bool is_vec>
16  struct finite {
17  static bool check(const char* function,
18  const T_y& y,
19  const char* name,
20  T_result* result) {
21  if (!(boost::math::isfinite)(y))
22  return dom_err(function,y,name,
23  " is %1%, but must be finite!","",
24  result);
25  return true;
26  }
27  };
28 
29  template <typename T_y, typename T_result>
30  struct finite<T_y, T_result, true> {
31  static bool check(const char* function,
32  const T_y& y,
33  const char* name,
34  T_result* result) {
35  using stan::length;
36  for (size_t n = 0; n < length(y); n++) {
37  if (!(boost::math::isfinite)(stan::get(y,n)))
38  return dom_err_vec(n,function,y,name,
39  " is %1%, but must be finite!","",
40  result);
41  }
42  return true;
43  }
44  };
45  }
46 
51  template <typename T_y, typename T_result>
52  inline bool check_finite(const char* function,
53  const T_y& y,
54  const char* name,
55  T_result* result) {
56  return finite<T_y,T_result,is_vector_like<T_y>::value>
57  ::check(function, y, name, result);
58  }
59  }
60 }
61 #endif
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
bool isfinite(const stan::agrad::var &v)
Checks if the given number has finite value.
size_t length(const T &)
Definition: traits.hpp:159
bool check_finite(const char *function, const T_y &y, const char *name, T_result *result)
Checks if the variable y is finite.
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.