Stan Math Library: stan/math/prim/scal/err/check_finite.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
4 #include <stan/math/prim/scal/err/domain_error.hpp>
5 #include <stan/math/prim/scal/err/domain_error_vec.hpp>
6 #include <stan/math/prim/scal/meta/length.hpp>
7 #include <stan/math/prim/scal/meta/is_vector_like.hpp>
8 #include <stan/math/prim/scal/fun/value_of_rec.hpp>
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) {
20 using stan::math::value_of_rec;
21 if (!(boost::math::isfinite)(value_of_rec(y)))
22 domain_error(function, name, y,
23 "is ", ", but must be finite!");
24 return true;
25 }
26 };
27
28 template <typename T_y>
29 struct finite<T_y, true> {
30 static bool check(const char* function,
31 const char* name,
32 const T_y& y) {
33 using stan::math::value_of_rec;
34 using stan::length;
35 for (size_t n = 0; n < length(y); n++) {
36 if (!(boost::math::isfinite)(value_of_rec(stan::get(y, n))))
37 domain_error_vec(function, name, y, n,
38 "is ", ", but must be finite!");
39 }
40 return true;
41 }
42 };
43 }
44
61 template <typename T_y>
62 inline bool check_finite(const char* function,
63 const char* name,
64 const T_y& y) {
65 return finite<T_y, is_vector_like<T_y>::value>
66 ::check(function, name, y);
67 }
68 }
69 }
70 #endif
boost::math::isfinite
bool isfinite(const stan::math::var &v)
Checks if the given number has finite value.
Definition: boost_isfinite.hpp:22
stan
Definition: log_sum_exp.hpp:8
stan::math::value_of_rec
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
Definition: value_of_rec.hpp:21
stan::length
size_t length(const std::vector< T > &x)
Definition: length.hpp:10
domain_error_vec.hpp
is_vector_like.hpp
stan::math::domain_error_vec
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.
Definition: domain_error_vec.hpp:38
stan::get
T get(const std::vector< T > &x, size_t n)
Definition: get.hpp:10
stan::math::domain_error
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.
Definition: domain_error.hpp:32
value_of_rec.hpp
length.hpp
stan::math::check_finite
bool check_finite(const char *function, const char *name, const T_y &y)
Return true if y is finite.
Definition: check_finite.hpp:62
domain_error.hpp

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