Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
check_finite.hpp
Go to the documentation of this file.
1 #ifndef __STAN__MATH__ERROR_HANDLING__CHECK_FINITE_HPP__
2 #define __STAN__MATH__ERROR_HANDLING__CHECK_FINITE_HPP__
3 
7 
8 namespace stan {
9  namespace math {
10 
11  namespace {
12  template <typename T_y,
13  typename T_result,
14  class Policy,
15  bool is_vec>
16  struct finite {
17  static bool check(const char* function,
18  const T_y& y,
19  const char* name,
20  T_result* result,
21  const Policy&) {
22  if (!(boost::math::isfinite)(y))
23  return dom_err(function,y,name,
24  " is %1%, but must be finite!","",
25  result,Policy());
26  return true;
27  }
28  };
29 
30  template <typename T_y,
31  typename T_result,
32  class Policy>
33  struct finite<T_y, T_result, Policy, true> {
34  static bool check(const char* function,
35  const T_y& y,
36  const char* name,
37  T_result* result,
38  const Policy&) {
39  using stan::length;
40  for (size_t n = 0; n < length(y); n++) {
41  if (!(boost::math::isfinite)(stan::get(y,n)))
42  return dom_err_vec(n,function,y,name,
43  " is %1%, but must be finite!","",
44  result,Policy());
45  }
46  return true;
47  }
48  };
49  }
53  template <typename T_y, typename T_result, class Policy>
54  inline bool check_finite(const char* function,
55  const T_y& y,
56  const char* name,
57  T_result* result,
58  const Policy&) {
59  return finite<T_y,T_result,Policy,
61  ::check(function, y, name, result, Policy());
62  }
63 
64  template <typename T_y, typename T_result>
65  inline bool check_finite(const char* function,
66  const T_y& y,
67  const char* name,
68  T_result* result) {
69  return check_finite(function,y,name,result,default_policy());
70  }
71 
72  template <typename T>
73  inline bool check_finite(const char* function,
74  const T& y,
75  const char* name) {
76  return check_finite<T,typename scalar_type<T>::type *>
77  (function,y,name,0,default_policy());
78  }
79 
80  }
81 }
82 #endif

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