Stan Math Library  2.20.0
reverse mode automatic differentiation
check_nan.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_OPENCL_ERR_CHECK_NAN_HPP
2 #define STAN_MATH_OPENCL_ERR_CHECK_NAN_HPP
3 #ifdef STAN_OPENCL
9 
10 #include <vector>
11 
12 namespace stan {
13 namespace math {
24 inline void check_nan(const char* function, const char* name,
25  const matrix_cl& y) {
26  if (y.size() == 0)
27  return;
28  try {
29  int nan_flag = 0;
30  matrix_cl nan_chk(1, 1);
31  nan_chk = to_matrix_cl(nan_flag);
32  opencl_kernels::check_nan(cl::NDRange(y.rows(), y.cols()), y, nan_chk,
33  y.rows(), y.cols());
34  nan_flag = from_matrix_cl<int>(nan_chk);
35  if (nan_flag) {
36  domain_error(function, name, "has NaN values", "");
37  }
38  } catch (const cl::Error& e) {
39  check_opencl_error("nan_check", e);
40  }
41 }
42 
43 } // namespace math
44 } // namespace stan
45 #endif
46 #endif
The matrix_cl class - allocates memory space on the OpenCL device, functions for transfering matrices...
const kernel_cl< in_buffer, out_buffer, int, int > check_nan("is_nan", {indexing_helpers, is_nan_kernel_code})
See the docs for is_nan() .
Represents a matrix on the OpenCL device.
Definition: matrix_cl.hpp:29
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.
double e()
Return the base of the natural logarithm.
Definition: constants.hpp:87
matrix_cl to_matrix_cl(const Eigen::Matrix< double, R, C > &src)
Copies the source Eigen matrix to the destination matrix that is stored on the OpenCL device...
Definition: copy.hpp:37
void check_opencl_error(const char *function, const cl::Error &e)
Throws the domain error with specifying the OpenCL error that occured.
void check_nan(const char *function, const char *name, const matrix_cl &y)
Check if the matrix_cl has NaN values.
Definition: check_nan.hpp:24

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