Stan Math Library  2.20.0
reverse mode automatic differentiation
check_diagonal_zeros.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_OPENCL_ERR_CHECK_DIAGONAL_ZEROS_HPP
2 #define STAN_MATH_OPENCL_ERR_CHECK_DIAGONAL_ZEROS_HPP
3 #ifdef STAN_OPENCL
9 #include <vector>
10 
11 namespace stan {
12 namespace math {
23 inline void check_diagonal_zeros(const char* function, const char* name,
24  const matrix_cl& y) {
25  if (y.size() == 0)
26  return;
27  cl::CommandQueue cmd_queue = opencl_context.queue();
28  cl::Context ctx = opencl_context.context();
29  try {
30  int zero_on_diagonal_flag = 0;
31  matrix_cl zeros_flag(1, 1);
32  zeros_flag = to_matrix_cl(zero_on_diagonal_flag);
33  opencl_kernels::check_diagonal_zeros(cl::NDRange(y.rows(), y.cols()), y,
34  zeros_flag, y.rows(), y.cols());
35  zero_on_diagonal_flag = from_matrix_cl<int>(zeros_flag);
36  // if zeros were found on the diagonal
37  if (zero_on_diagonal_flag) {
38  domain_error(function, name, "has zeros on the diagonal.", "");
39  }
40  } catch (const cl::Error& e) {
41  check_opencl_error("diag_zeros_check", e);
42  }
43 }
44 
45 } // namespace math
46 } // namespace stan
47 #endif
48 #endif
void check_diagonal_zeros(const char *function, const char *name, const matrix_cl &y)
Check if the matrix_cl has zeros on the diagonal.
The API to access the methods and values in opencl_context_base.
The matrix_cl class - allocates memory space on the OpenCL device, functions for transfering matrices...
Represents a matrix on the OpenCL device.
Definition: matrix_cl.hpp:29
cl::Context & context()
Returns the reference to the OpenCL context.
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
const kernel_cl< in_buffer, out_buffer, int, int > check_diagonal_zeros("is_zero_on_diagonal", {indexing_helpers, is_zero_on_diagonal_kernel_code})
See the docs for check_diagonal_zeros() .
void check_opencl_error(const char *function, const cl::Error &e)
Throws the domain error with specifying the OpenCL error that occured.
cl::CommandQueue & queue()
Returns the reference to the active OpenCL command queue for the device.

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