Automatic Differentiation
 
Loading...
Searching...
No Matches
matrix_cl_view.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_TRIANGULAR_HPP
2#define STAN_MATH_OPENCL_TRIANGULAR_HPP
3#ifdef STAN_OPENCL
4
7#include <type_traits>
8
9namespace stan {
10namespace math {
11enum class matrix_cl_view { Diagonal = 0, Lower = 1, Upper = 2, Entire = 3 };
12
19inline const matrix_cl_view either(const matrix_cl_view left_view,
20 const matrix_cl_view right_view) {
21 using underlying = typename std::underlying_type<matrix_cl_view>::type;
22 return static_cast<matrix_cl_view>(static_cast<underlying>(left_view)
23 | static_cast<underlying>(right_view));
24}
25
32inline const matrix_cl_view both(const matrix_cl_view left_view,
33 const matrix_cl_view right_view) {
34 using underlying = typename std::underlying_type<matrix_cl_view>::type;
35 return static_cast<matrix_cl_view>(static_cast<underlying>(left_view)
36 & static_cast<underlying>(right_view));
37}
38
45inline bool contains_nonzero(const matrix_cl_view view,
46 const matrix_cl_view part) {
47 return static_cast<bool>(both(view, part));
48}
49
55inline const matrix_cl_view transpose(const matrix_cl_view view) {
56 if (view == matrix_cl_view::Lower) {
58 }
59 if (view == matrix_cl_view::Upper) {
61 }
62 return view;
63}
64
71inline const matrix_cl_view invert(const matrix_cl_view view) {
72 using underlying = typename std::underlying_type<matrix_cl_view>::type;
73 return static_cast<matrix_cl_view>(
74 static_cast<underlying>(matrix_cl_view::Entire)
75 & ~static_cast<underlying>(view));
76}
77
86inline matrix_cl_view from_eigen_uplo_type(Eigen::UpLoType eigen_type) {
87 if (eigen_type & Eigen::Lower) {
89 }
90 if (eigen_type & Eigen::Upper) {
92 }
94}
95
96// \cond
97static constexpr const char* view_kernel_helpers = STRINGIFY(
98 // \endcond
105 int either(int left_view, int right_view) { return left_view | right_view; }
106
113 int both(int left_view, int right_view) { return left_view & right_view; }
114
121 bool contains_nonzero(int view, int part) { return both(view, part); }
122 // \cond
123);
124// \endcond
125
126} // namespace math
127} // namespace stan
128#endif
129#endif
auto transpose(Arg &&a)
Transposes a kernel generator expression.
matrix_cl_view from_eigen_uplo_type(Eigen::UpLoType eigen_type)
Creates a view from Eigen::UpLoType.
const matrix_cl_view both(const matrix_cl_view left_view, const matrix_cl_view right_view)
Determines which parts are nonzero in both input views.
const matrix_cl_view invert(const matrix_cl_view view)
Inverts a view.
const matrix_cl_view either(const matrix_cl_view left_view, const matrix_cl_view right_view)
Determines which parts are nonzero in any of the input views.
bool contains_nonzero(const matrix_cl_view view, const matrix_cl_view part)
Check whether a view contains certain nonzero part.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9
#define STRINGIFY(...)
Definition stringify.hpp:9