Stan Math Library  2.20.0
reverse mode automatic differentiation
unpack.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_OPENCL_KERNELS_UNPACK_HPP
2 #define STAN_MATH_OPENCL_KERNELS_UNPACK_HPP
3 #ifdef STAN_OPENCL
4 
7 
8 namespace stan {
9 namespace math {
10 namespace opencl_kernels {
11 // \cond
12 static const char* unpack_kernel_code = STRINGIFY(
13  // \endcond
31  __kernel void unpack(__global double* B, __global double* A,
32  unsigned int rows, unsigned int cols,
33  unsigned int part) {
34  int i = get_global_id(0);
35  int j = get_global_id(1);
36  if (i < rows && j < cols) {
37  // the packed matrices are stored in row major
38  if (part == LOWER) {
39  const int column_offset = j * rows - (j * (j - 1)) / 2;
40  const int row_offset = (i - j);
41  if (j <= i) {
42  B(i, j) = A[column_offset + row_offset];
43  } else {
44  B(i, j) = 0.0;
45  }
46  } else {
47  const int column_offset = j * (j + 1) / 2;
48  if (j >= i) {
49  B(i, j) = A[column_offset + i];
50  } else {
51  B(i, j) = 0.0;
52  }
53  }
54  }
55  }
56  // \cond
57 );
58 // \endcond
59 
64  "unpack", {indexing_helpers, unpack_kernel_code});
65 
66 } // namespace opencl_kernels
67 } // namespace math
68 } // namespace stan
69 #endif
70 #endif
int rows(const Eigen::Matrix< T, R, C > &m)
Return the number of rows in the specified matrix, vector, or row vector.
Definition: rows.hpp:20
const kernel_cl< out_buffer, in_buffer, int, int, TriangularViewCL > unpack("unpack", {indexing_helpers, unpack_kernel_code})
See the docs for unpack() .
#define STRINGIFY(src)
Definition: kernel_cl.hpp:22
static const char * indexing_helpers
Definition: helpers.hpp:14
int cols(const Eigen::Matrix< T, R, C > &m)
Return the number of columns in the specified matrix, vector, or row vector.
Definition: cols.hpp:20
Creates functor for kernels.
Definition: kernel_cl.hpp:201

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