1#ifndef STAN_MATH_OPENCL_KERNELS_gp_MATERN52_COV_HPP
2#define STAN_MATH_OPENCL_KERNELS_gp_MATERN52_COV_HPP
10namespace opencl_kernels {
12static constexpr const char* gp_matern52_cov_kernel_code =
STRINGIFY(
26 const __global
double* x, __global
double* res,
const double sigma_sq,
27 const double root_5_inv_l,
const double inv_l_sq_5_3,
const int size,
28 const int element_size) {
29 const int i = get_global_id(0);
30 const int j = get_global_id(1);
34 for (
int k = 0; k < element_size; k++) {
35 double d = x[i * element_size + k] - x[j * element_size + k];
39 double a = sigma_sq * (1.0 + root_5_inv_l * dist + inv_l_sq_5_3 *
sum)
40 *
exp(-root_5_inv_l * dist);
41 res[j *
size + i] = a;
42 res[i *
size + j] = a;
44 res[j *
size + i] = sigma_sq;
55const kernel_cl<in_buffer, out_buffer, double, double, double, int, int>
59static constexpr const char* gp_matern52_cov_cross_kernel_code =
STRINGIFY(
79 const __global
double* x1,
const __global
double* x2,
80 __global
double* res,
const double sigma_sq,
const double root_5_inv_l,
81 const double inv_l_sq_5_3,
const int size1,
const int size2,
82 const int element_size) {
83 const int i = get_global_id(0);
84 const int j = get_global_id(1);
85 if (i < size1 && j < size2) {
87 for (
int k = 0; k < element_size; k++) {
88 double d = x1[i * element_size + k] - x2[j * element_size + k];
92 res[j * size1 + i] = sigma_sq
93 * (1.0 + root_5_inv_l * dist + inv_l_sq_5_3 *
sum)
94 *
exp(-root_5_inv_l * dist);
105const kernel_cl<in_buffer, in_buffer, out_buffer, double, double, double, int,
108 {gp_matern52_cov_cross_kernel_code});
const kernel_cl< in_buffer, out_buffer, double, double, double, int, int > gp_matern52_cov("gp_matern52_cov", {gp_matern52_cov_kernel_code})
See the docs for gp_matern52_cov() .
const kernel_cl< in_buffer, in_buffer, out_buffer, double, double, double, int, int, int > gp_matern52_cov_cross("gp_matern52_cov_cross", {gp_matern52_cov_cross_kernel_code})
See the docs for gp_matern52_cov_cross() .
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
fvar< T > sqrt(const fvar< T > &x)
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
fvar< T > exp(const fvar< T > &x)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...