Stan Math Library  2.14.0
reverse mode automatic differentiation
check_not_nan.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_ERR_CHECK_NOT_NAN_HPP
2 #define STAN_MATH_PRIM_SCAL_ERR_CHECK_NOT_NAN_HPP
3 
10 
11 namespace stan {
12  namespace math {
13 
14  namespace {
15  template <typename T_y, bool is_vec>
16  struct not_nan {
17  static void check(const char* function,
18  const char* name,
19  const T_y& y) {
20  if (is_nan(value_of_rec(y)))
21  domain_error(function, name, y,
22  "is ", ", but must not be nan!");
23  }
24  };
25 
26  template <typename T_y>
27  struct not_nan<T_y, true> {
28  static void check(const char* function,
29  const char* name,
30  const T_y& y) {
31  for (size_t n = 0; n < stan::length(y); n++) {
32  if (is_nan(value_of_rec(stan::get(y, n))))
33  domain_error_vec(function, name, y, n,
34  "is ", ", but must not be nan!");
35  }
36  }
37  };
38  }
39 
56  template <typename T_y>
57  inline void check_not_nan(const char* function,
58  const char* name,
59  const T_y& y) {
60  not_nan<T_y, is_vector_like<T_y>::value>::check(function, name, y);
61  }
62 
63  }
64 }
65 #endif
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, size_t i, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
void check_not_nan(const char *function, const char *name, const T_y &y)
Check if y is not NaN.
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.
int is_nan(const fvar< T > &x)
Returns 1 if the input&#39;s value is NaN and 0 otherwise.
Definition: is_nan.hpp:21

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