Automatic Differentiation
 
Loading...
Searching...
No Matches
gp_matern52_cov.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_KERNELS_gp_MATERN52_COV_HPP
2#define STAN_MATH_OPENCL_KERNELS_gp_MATERN52_COV_HPP
3#ifdef STAN_OPENCL
4
6#include <string>
7
8namespace stan {
9namespace math {
10namespace opencl_kernels {
11// \cond
12static constexpr const char* gp_matern52_cov_kernel_code = STRINGIFY(
13 // \endcond
25 __kernel void gp_matern52_cov(
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);
31 if (i < size && j < size) {
32 if (i > j) {
33 double sum = 0;
34 for (int k = 0; k < element_size; k++) {
35 double d = x[i * element_size + k] - x[j * element_size + k];
36 sum += d * d;
37 }
38 double dist = sqrt(sum);
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;
43 } else if (i == j) {
44 res[j * size + i] = sigma_sq;
45 }
46 }
47 }
48 // \cond
49);
50// \endcond
51
55const kernel_cl<in_buffer, out_buffer, double, double, double, int, int>
56 gp_matern52_cov("gp_matern52_cov", {gp_matern52_cov_kernel_code});
57
58// \cond
59static constexpr const char* gp_matern52_cov_cross_kernel_code = STRINGIFY(
60 // \endcond
78 __kernel void gp_matern52_cov_cross(
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) {
86 double sum = 0;
87 for (int k = 0; k < element_size; k++) {
88 double d = x1[i * element_size + k] - x2[j * element_size + k];
89 sum += d * d;
90 }
91 double dist = sqrt(sum);
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);
95 }
96 }
97 // \cond
98);
99// \endcond
100
105const kernel_cl<in_buffer, in_buffer, out_buffer, double, double, double, int,
106 int, int>
107 gp_matern52_cov_cross("gp_matern52_cov_cross",
108 {gp_matern52_cov_cross_kernel_code});
109
110} // namespace opencl_kernels
111} // namespace math
112} // namespace stan
113#endif
114#endif
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>>.
Definition size.hpp:19
fvar< T > sqrt(const fvar< T > &x)
Definition sqrt.hpp:17
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
Definition sum.hpp:23
fvar< T > exp(const fvar< T > &x)
Definition exp.hpp:13
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
#define STRINGIFY(...)
Definition stringify.hpp:9