Stan Math Library  2.20.0
reverse mode automatic differentiation
check_finite.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_FINITE_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_FINITE_HPP
3 
9 #include <boost/math/special_functions/fpclassify.hpp>
10 
11 namespace stan {
12 namespace math {
13 
14 /*
15  * Return <code>true</code> is the specified matrix is finite.
16  * @tparams T Scalar type of the matrix, requires class method
17  * <code>.size()</code>
18  * @tparams R Compile time rows of the matrix
19  * @tparams C Compile time columns of the matrix
20  * @param function Function name (for error messages)
21  * @param name Variable name (for error messages)
22  * @param y Matrix to test
23  * @return <code>true</code> if the matrix is finite
24  **/
25 namespace internal {
26 template <typename T, int R, int C>
27 struct finite<Eigen::Matrix<T, R, C>, true> {
28  static void check(const char* function, const char* name,
29  const Eigen::Matrix<T, R, C>& y) {
30  if (!value_of(y).allFinite()) {
31  for (int n = 0; n < y.size(); ++n) {
32  if (!(boost::math::isfinite)(y(n)))
33  domain_error_vec(function, name, y, n, "is ",
34  ", but must be finite!");
35  }
36  }
37  }
38 };
39 } // namespace internal
40 } // namespace math
41 } // namespace stan
42 
43 #endif
bool isfinite(const stan::math::var &v)
Checks if the given number has finite value.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition: value_of.hpp:17
void domain_error_vec(const char *function, const char *name, const T &y, size_t i, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
(Expert) Numerical traits for algorithmic differentiation variables.
static void check(const char *function, const char *name, const Eigen::Matrix< T, R, C > &y)

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