Automatic Differentiation
 
Loading...
Searching...
No Matches
gp_matern32_cov.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_KERNELS_GP_MATERN32_COV_HPP
2#define STAN_MATH_OPENCL_KERNELS_GP_MATERN32_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_matern32_cov_kernel_code = STRINGIFY(
13 // \endcond
24 __kernel void gp_matern32_cov(
25 const __global double* x, __global double* res, const double sigma_sq,
26 const double root_3_inv_l, const int size, const int element_size) {
27 const int i = get_global_id(0);
28 const int j = get_global_id(1);
29 if (i < size && j < size) {
30 if (i > j) {
31 double sum = 0;
32 for (int k = 0; k < element_size; k++) {
33 double d = x[i * element_size + k] - x[j * element_size + k];
34 sum += d * d;
35 }
36 double dist = sqrt(sum);
37 double a = sigma_sq * (1.0 + root_3_inv_l * dist)
38 * exp(-root_3_inv_l * dist);
39 res[j * size + i] = a;
40 res[i * size + j] = a;
41 } else if (i == j) {
42 res[j * size + i] = sigma_sq;
43 }
44 }
45 }
46 // \cond
47);
48// \endcond
49
53const kernel_cl<in_buffer, out_buffer, double, double, int, int>
54 gp_matern32_cov("gp_matern32_cov", {gp_matern32_cov_kernel_code});
55
56// \cond
57static constexpr const char* gp_matern32_cov_cross_kernel_code = STRINGIFY(
58 // \endcond
75 __kernel void gp_matern32_cov_cross(
76 const __global double* x1, const __global double* x2,
77 __global double* res, const double sigma_sq, const double root_3_inv_l,
78 const int size1, const int size2, const int element_size) {
79 const int i = get_global_id(0);
80 const int j = get_global_id(1);
81 if (i < size1 && j < size2) {
82 double sum = 0;
83 for (int k = 0; k < element_size; k++) {
84 double d = x1[i * element_size + k] - x2[j * element_size + k];
85 sum += d * d;
86 }
87 double dist = sqrt(sum);
88 res[j * size1 + i] = sigma_sq * (1.0 + root_3_inv_l * dist)
89 * exp(-root_3_inv_l * dist);
90 }
91 }
92 // \cond
93);
94// \endcond
95
100const kernel_cl<in_buffer, in_buffer, out_buffer, double, double, int, int, int>
101 gp_matern32_cov_cross("gp_matern32_cov_cross",
102 {gp_matern32_cov_cross_kernel_code});
103
104} // namespace opencl_kernels
105} // namespace math
106} // namespace stan
107#endif
108#endif
const kernel_cl< in_buffer, out_buffer, double, double, int, int > gp_matern32_cov("gp_matern32_cov", {gp_matern32_cov_kernel_code})
See the docs for gp_matern32_cov() .
const kernel_cl< in_buffer, in_buffer, out_buffer, double, double, int, int, int > gp_matern32_cov_cross("gp_matern32_cov_cross", {gp_matern32_cov_cross_kernel_code})
See the docs for gp_matern32_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