All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
check_finite.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_FINITE_HPP
#define STAN_MATH_PRIM_SCAL_ERR_CHECK_FINITE_HPP
#include <stan/math/prim/scal/err/domain_error.hpp>
#include <stan/math/prim/scal/err/domain_error_vec.hpp>
#include <stan/math/prim/scal/meta/length.hpp>
#include <stan/math/prim/scal/meta/is_vector_like.hpp>
#include <stan/math/prim/scal/fun/value_of_rec.hpp>
#include <boost/math/special_functions/fpclassify.hpp>
namespace stan {
namespace math {
namespace {
template <typename T_y, bool is_vec>
struct finite {
static bool check(const char* function,
const char* name,
const T_y& y) {
using stan::math::value_of_rec;
if (!(boost::math::isfinite)(value_of_rec(y)))
domain_error(function, name, y,
"is ", ", but must be finite!");
return true;
}
};
template <typename T_y>
struct finite<T_y, true> {
static bool check(const char* function,
const char* name,
const T_y& y) {
using stan::math::value_of_rec;
using stan::length;
for (size_t n = 0; n < length(y); n++) {
if (!(boost::math::isfinite)(value_of_rec(stan::get(y, n))))
domain_error_vec(function, name, y, n,
"is ", ", but must be finite!");
}
return true;
}
};
}
template <typename T_y>
inline bool check_finite(const char* function,
const char* name,
const T_y& y) {
return finite<T_y, is_vector_like<T_y>::value>
::check(function, name, y);
}
}
}
#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::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–2015, Stan Development Team.