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 void check(const char* function, const char* name, const T_y& y) {
19  domain_error(function, name, y, "is ", ", but must be finite!");
20  }
21 };
22 
23 template <typename T_y>
24 struct finite<T_y, true> {
25  static void check(const char* function, const char* name, const T_y& y) {
26  using stan::length;
27  for (size_t n = 0; n < length(y); n++) {
29  domain_error_vec(function, name, y, n, "is ", ", but must be finite!");
30  }
31  }
32 };
33 } // namespace
34 
35 /**
36  * Check if <code>y</code> is finite.
37  *
38  * This function is vectorized and will check each element of
39  * <code>y</code>.
40  *
41  * @tparam T_y Type of y
42  *
43  * @param function Function name (for error messages)
44  * @param name Variable name (for error messages)
45  * @param y Variable to check
46  *
47  * @throw <code>domain_error</code> if y is infinity, -infinity, or
48  * NaN.
49  */
50 template <typename T_y>
51 inline void check_finite(const char* function, const char* name, const T_y& y) {
52  finite<T_y, is_vector_like<T_y>::value>::check(function, name, y);
53 }
54 } // namespace math
55 } // namespace stan
56 #endif
const XML_Char * name
Definition: expat.h:151
void check_finite(const char *function, const char *name, const T_y &y)
bool isfinite(const stan::math::var &v)
double value_of_rec(const fvar< T > &v)
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, size_t i, const char *msg1, const char *msg2)
const XML_Char int const XML_Char * value
Definition: expat.h:331
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)