12#include "detray/algebra/common/math.hpp"
13#include "detray/algebra/concepts.hpp"
14#include "detray/definitions/detail/qualifiers.hpp"
18#pragma warning(push, 0)
20#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
21#pragma nv_diagnostic push
22#pragma nv_diag_suppress 20012
28#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
29#pragma nv_diagnostic pop
35namespace detray::algebra::eigen::storage {
46 requires std::is_base_of_v<
47 Eigen::DenseCoeffsBase<derived_type, Eigen::WriteAccessors>,
48 Eigen::MatrixBase<derived_type>>
50 Eigen::MatrixBase<derived_type> &m, index_t_1 row, index_t_2 col)
const {
51 return m(
static_cast<Eigen::Index
>(row),
static_cast<Eigen::Index
>(col));
61 const Eigen::MatrixBase<derived_type> &m, index_t_1 row,
62 index_t_2 col)
const {
63 return m(
static_cast<Eigen::Index
>(row),
static_cast<Eigen::Index
>(col));
69 template <
typename derived_type, concepts::index index_t>
70 requires std::is_base_of_v<
71 Eigen::DenseCoeffsBase<derived_type, Eigen::WriteAccessors>,
72 Eigen::MatrixBase<derived_type>>
74 Eigen::MatrixBase<derived_type> &m, index_t row)
const {
75 return m(
static_cast<Eigen::Index
>(row));
81 template <
typename derived_type, concepts::index index_t>
83 const Eigen::MatrixBase<derived_type> &m, index_t row)
const {
84 return m(
static_cast<Eigen::Index
>(row));
89template <
typename derived_type>
90DETRAY_HOST_DEVICE
constexpr decltype(
auto) element(
91 const Eigen::MatrixBase<derived_type> &m, std::size_t row,
93 return element_getter()(m,
static_cast<Eigen::Index
>(row),
94 static_cast<Eigen::Index
>(col));
98template <
typename derived_type>
99 requires std::is_base_of_v<
100 Eigen::DenseCoeffsBase<derived_type, Eigen::WriteAccessors>,
101 Eigen::MatrixBase<derived_type>>
102DETRAY_HOST_DEVICE
constexpr decltype(
auto) element(
103 Eigen::MatrixBase<derived_type> &m, std::size_t row, std::size_t col) {
104 return element_getter()(m,
static_cast<Eigen::Index
>(row),
105 static_cast<Eigen::Index
>(col));
109template <
typename derived_type>
110DETRAY_HOST_DEVICE
constexpr decltype(
auto) element(
111 const Eigen::MatrixBase<derived_type> &m, std::size_t row) {
112 return element_getter()(m,
static_cast<Eigen::Index
>(row));
116template <
typename derived_type>
117 requires std::is_base_of_v<
118 Eigen::DenseCoeffsBase<derived_type, Eigen::WriteAccessors>,
119 Eigen::MatrixBase<derived_type>>
120DETRAY_HOST_DEVICE
constexpr decltype(
auto) element(
121 Eigen::MatrixBase<derived_type> &m, std::size_t row) {
122 return element_getter()(m,
static_cast<Eigen::Index
>(row));
125template <std::
size_t I, std::
size_t J, concepts::matrix M>
126DETRAY_HOST_DEVICE
decltype(
auto) element(M &matrix) {
127 if constexpr (concepts::has_compile_time_2d_access<M>) {
128 return matrix.template element<I, J>();
130 using index_t = detray::traits::index_t<std::decay_t<M>>;
131 return element(matrix,
static_cast<index_t
>(I),
static_cast<index_t
>(J));
135template <std::
size_t I, concepts::vector V>
136DETRAY_HOST_DEVICE
decltype(
auto) element(V &vector) {
137 if constexpr (concepts::has_compile_time_1d_access<V>) {
138 return vector.template element<I>();
140 using index_t = detray::traits::index_t<std::decay_t<V>>;
141 return element(vector,
static_cast<index_t
>(I));
152 template <
int kROWS,
int kCOLS,
typename derived_type,
154 DETRAY_HOST_DEVICE
decltype(
auto)
operator()(
155 const Eigen::MatrixBase<derived_type> &m,
const index_t_1 row,
156 const index_t_2 col)
const {
157 return m.template block<kROWS, kCOLS>(row, col);
165 template <
int kROWS,
int kCOLS,
typename derived_type,
167 DETRAY_HOST_DEVICE
decltype(
auto)
operator()(
168 Eigen::MatrixBase<derived_type> &m,
const index_t_1 row,
169 const index_t_2 col)
const {
170 return m.template block<kROWS, kCOLS>(row, col);
180 DETRAY_HOST_DEVICE
decltype(
auto)
vector(Eigen::MatrixBase<derived_type> &m,
182 const index_t_2 col)
const {
183 return m.template block<SIZE, 1>(row, col);
193 DETRAY_HOST_DEVICE
decltype(
auto)
vector(
194 const Eigen::MatrixBase<derived_type> &m,
const index_t_1 row,
195 const index_t_2 col)
const {
196 return m.template block<SIZE, 1>(row, col);
204 template <
typename derived_type1,
typename derived_type2,
206 DETRAY_HOST_DEVICE
void set(Eigen::MatrixBase<derived_type1> &m,
207 const Eigen::MatrixBase<derived_type2> &b,
208 const index_t_1 row,
const index_t_2 col)
const {
209 using block_t = Eigen::MatrixBase<derived_type2>;
210 constexpr auto R{block_t::RowsAtCompileTime};
211 constexpr auto C{block_t::ColsAtCompileTime};
212 m.template block<R, C>(
static_cast<Eigen::Index
>(row),
213 static_cast<Eigen::Index
>(col)) = b;
219template <
int ROWS,
int COLS,
class derived_type>
220DETRAY_HOST_DEVICE
decltype(
auto) block(
221 const Eigen::MatrixBase<derived_type> &m, std::size_t row,
223 return block_getter{}.template operator()<ROWS, COLS>(
224 m,
static_cast<Eigen::Index
>(row),
static_cast<Eigen::Index
>(col));
228template <
int ROWS,
int COLS,
class derived_type>
229DETRAY_HOST_DEVICE
decltype(
auto) block(Eigen::MatrixBase<derived_type> &m,
230 std::size_t row, std::size_t col) {
231 return block_getter{}.template operator()<ROWS, COLS>(
232 m,
static_cast<Eigen::Index
>(row),
static_cast<Eigen::Index
>(col));
236template <
int SIZE,
typename derived_type>
237DETRAY_HOST_DEVICE
constexpr decltype(
auto) vector(
238 const Eigen::MatrixBase<derived_type> &m, std::size_t row,
240 return block_getter{}.template vector<SIZE>(m,
static_cast<Eigen::Index
>(row),
241 static_cast<Eigen::Index
>(col));
245template <
typename derived_type1,
typename derived_type2>
246DETRAY_HOST_DEVICE
void set_block(Eigen::MatrixBase<derived_type1> &m,
247 const Eigen::MatrixBase<derived_type2> &b,
248 std::size_t row, std::size_t col) {
250 static_cast<Eigen::Index
>(col));
Index concept to access vector/matrix elements.
Definition concepts.hpp:54
Functor used to extract a block from Eigen matrices.
Definition eigen_getter.hpp:146
decltype(auto) vector(Eigen::MatrixBase< derived_type > &m, const index_t_1 row, const index_t_2 col) const
Return a mutable column segment from a matrix.
Definition eigen_getter.hpp:180
decltype(auto) vector(const Eigen::MatrixBase< derived_type > &m, const index_t_1 row, const index_t_2 col) const
Return a const column segment from a matrix.
Definition eigen_getter.hpp:193
void set(Eigen::MatrixBase< derived_type1 > &m, const Eigen::MatrixBase< derived_type2 > &b, const index_t_1 row, const index_t_2 col) const
Operator setting a block.
Definition eigen_getter.hpp:206
Functor used to access elements of Eigen matrices.
Definition eigen_getter.hpp:38
constexpr auto operator()(const Eigen::MatrixBase< derived_type > &m, index_t row) const
Get const access to a matrix element.
Definition eigen_getter.hpp:82
constexpr auto & operator()(Eigen::MatrixBase< derived_type > &m, index_t_1 row, index_t_2 col) const
Get non-const access to a matrix element.
Definition eigen_getter.hpp:49
constexpr auto operator()(const Eigen::MatrixBase< derived_type > &m, index_t_1 row, index_t_2 col) const
Get const access to a matrix element.
Definition eigen_getter.hpp:60
constexpr auto & operator()(Eigen::MatrixBase< derived_type > &m, index_t row) const
Get non-const access to a matrix element.
Definition eigen_getter.hpp:73