Stan Math Library  2.12.0
reverse mode automatic differentiation
check_finite.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_FINITE_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_CHECK_FINITE_HPP
3 
9 #include <boost/math/special_functions/fpclassify.hpp>
10 
11 namespace stan {
12  namespace math {
13 
14  namespace {
15  template <typename T_y, bool is_vec>
16  struct finite {
17  static bool check(const char* function,
18  const char* name,
19  const T_y& y) {
21  domain_error(function, name, y,
22  "is ", ", but must be finite!");
23  return true;
24  }
25  };
26 
27  template <typename T_y>
28  struct finite<T_y, true> {
29  static bool check(const char* function,
30  const char* name,
31  const T_y& y) {
32  using stan::length;
33  for (size_t n = 0; n < length(y); n++) {
35  domain_error_vec(function, name, y, n,
36  "is ", ", but must be finite!");
37  }
38  return true;
39  }
40  };
41  }
42 
59  template <typename T_y>
60  inline bool check_finite(const char* function,
61  const char* name,
62  const T_y& y) {
63  return finite<T_y, is_vector_like<T_y>::value>
64  ::check(function, name, y);
65  }
66  }
67 }
68 #endif
bool isfinite(const stan::math::var &v)
Checks if the given number has finite value.
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
size_t length(const std::vector< T > &x)
Definition: length.hpp:10
void domain_error_vec(const char *function, const char *name, const T &y, const size_t i, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
T get(const std::vector< T > &x, size_t n)
Definition: get.hpp:10
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
bool check_finite(const char *function, const char *name, const T_y &y)
Return true if y is finite.

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