12#include "detray/algebra/concepts.hpp"
13#include "detray/definitions/detail/qualifiers.hpp"
16#include <Math/Expression.h>
17#include <Math/Functions.h>
18#include <Math/SMatrix.h>
19#include <Math/SVector.h>
25namespace detray::algebra::smatrix::storage {
34 template <
unsigned int ROWS,
unsigned int COLS, concepts::scalar scalar_t>
36 ROOT::Math::SMatrix<scalar_t, ROWS, COLS> &m,
unsigned int row,
37 unsigned int col)
const {
48 template <
unsigned int ROWS,
unsigned int COLS, concepts::scalar scalar_t>
50 const ROOT::Math::SMatrix<scalar_t, ROWS, COLS> &m,
unsigned int row,
51 unsigned int col)
const {
61 template <
unsigned int N, concepts::scalar scalar_t>
63 ROOT::Math::SMatrix<scalar_t, N, 1> &m,
unsigned int row)
const {
72 template <
unsigned int N, concepts::scalar scalar_t>
74 const ROOT::Math::SMatrix<scalar_t, N, 1> &m,
unsigned int row)
const {
83 template <concepts::scalar scalar_t,
unsigned int N>
85 ROOT::Math::SVector<scalar_t, N> &m,
unsigned int row)
const {
94 template <
unsigned int N, concepts::scalar scalar_t>
96 const ROOT::Math::SVector<scalar_t, N> &m,
unsigned int row)
const {
103template <concepts::scalar scalar_t,
unsigned int ROWS,
unsigned int COLS>
104DETRAY_HOST_DEVICE
constexpr scalar_t element(
105 const ROOT::Math::SMatrix<scalar_t, ROWS, COLS> &m, std::size_t row,
107 return element_getter()(m,
static_cast<unsigned int>(row),
108 static_cast<unsigned int>(col));
112template <concepts::scalar scalar_t,
unsigned int ROWS,
unsigned int COLS>
113DETRAY_HOST_DEVICE
constexpr scalar_t &element(
114 ROOT::Math::SMatrix<scalar_t, ROWS, COLS> &m, std::size_t row,
116 return element_getter()(m,
static_cast<unsigned int>(row),
117 static_cast<unsigned int>(col));
121template <concepts::scalar scalar_t,
unsigned int N>
122DETRAY_HOST_DEVICE
constexpr scalar_t element(
123 const ROOT::Math::SMatrix<scalar_t, N, 1> &m, std::size_t row) {
124 return element_getter()(m,
static_cast<unsigned int>(row));
128template <concepts::scalar scalar_t,
unsigned int N>
129DETRAY_HOST_DEVICE
constexpr scalar_t &element(
130 ROOT::Math::SMatrix<scalar_t, N, 1> &m, std::size_t row) {
131 return element_getter()(m,
static_cast<unsigned int>(row));
135template <concepts::scalar scalar_t,
unsigned int N>
136DETRAY_HOST_DEVICE
constexpr scalar_t element(
137 const ROOT::Math::SVector<scalar_t, N> &m, std::size_t row) {
142template <concepts::scalar scalar_t,
unsigned int N>
143DETRAY_HOST_DEVICE
constexpr scalar_t &element(
144 ROOT::Math::SVector<scalar_t, N> &m, std::size_t row) {
148template <std::
size_t I, std::
size_t J, concepts::matrix M>
149DETRAY_HOST_DEVICE
decltype(
auto) element(M &matrix) {
150 if constexpr (concepts::has_compile_time_2d_access<M>) {
151 return matrix.template element<I, J>();
153 using index_t = detray::traits::index_t<std::decay_t<M>>;
154 return element(matrix,
static_cast<index_t
>(I),
static_cast<index_t
>(J));
158template <std::
size_t I, concepts::vector V>
159DETRAY_HOST_DEVICE
decltype(
auto) element(V &vector) {
160 if constexpr (concepts::has_compile_time_1d_access<V>) {
161 return vector.template element<I>();
163 using index_t = detray::traits::index_t<std::decay_t<V>>;
164 return element(vector,
static_cast<index_t
>(I));
175 template <
unsigned int ROWS,
unsigned int COLS,
unsigned int oROWS,
177 DETRAY_HOST_DEVICE ROOT::Math::SMatrix<scalar_t, ROWS, COLS>
operator()(
178 const ROOT::Math::SMatrix<scalar_t, oROWS, oCOLS> &m,
unsigned int row,
179 unsigned int col)
const {
180 return m.template Sub<ROOT::Math::SMatrix<scalar_t, ROWS, COLS>>(row, col);
188 template <
unsigned int SIZE,
unsigned int ROWS,
unsigned int COLS,
190 DETRAY_HOST_DEVICE ROOT::Math::SVector<scalar_t, SIZE>
vector(
191 const ROOT::Math::SMatrix<scalar_t, ROWS, COLS> &m,
unsigned int row,
192 unsigned int col)
const {
198 assert(row + SIZE <= ROWS);
200 ROOT::Math::SVector<scalar_t, SIZE> ret;
202 for (
unsigned int irow = row; irow < row + SIZE; ++irow) {
203 ret[irow - row] = m(irow, col);
216 DETRAY_HOST_DEVICE
void set(
217 input_matrix_type &m,
const ROOT::Math::SMatrix<scalar_t, ROWS, COLS> &b,
218 std::size_t row, std::size_t col)
const {
219 for (
unsigned int i = 0; i < ROWS; ++i) {
220 for (
unsigned int j = 0; j < COLS; ++j) {
221 m(i +
static_cast<unsigned int>(row),
222 j +
static_cast<unsigned int>(col)) = b(i, j);
234 DETRAY_HOST_DEVICE
void set(input_matrix_type &m,
235 const ROOT::Math::SVector<scalar_t, ROWS> &b,
236 unsigned int row,
unsigned int col)
const {
237 for (
unsigned int i = 0; i < ROWS; ++i) {
238 m(i + row, col) = b[i];
245template <
unsigned int ROWS,
unsigned int COLS,
unsigned int oROWS,
247DETRAY_HOST_DEVICE ROOT::Math::SMatrix<scalar_t, ROWS, COLS> block(
248 const ROOT::Math::SMatrix<scalar_t, oROWS, oCOLS> &m, std::size_t row,
250 return block_getter{}.template operator()<ROWS, COLS>(
251 m,
static_cast<unsigned int>(row),
static_cast<unsigned int>(col));
256template <
unsigned int SIZE,
unsigned int ROWS,
unsigned int COLS,
258DETRAY_HOST_DEVICE
constexpr auto vector(
259 const ROOT::Math::SMatrix<scalar_t, ROWS, COLS> &m, std::size_t row,
261 return block_getter{}.template vector<SIZE>(m,
static_cast<unsigned int>(row),
262 static_cast<unsigned int>(col));
266template <
unsigned int ROWS,
unsigned int COLS, concepts::scalar scalar_t,
267 concepts::matrix input_matrix_type>
268DETRAY_HOST_DEVICE
void set_block(
269 input_matrix_type &m,
const ROOT::Math::SMatrix<scalar_t, ROWS, COLS> &b,
270 std::size_t row, std::size_t col) {
275template <
unsigned int ROWS, concepts::scalar scalar_t,
276 concepts::matrix input_matrix_type>
277DETRAY_HOST_DEVICE
void set_block(input_matrix_type &m,
278 const ROOT::Math::SVector<scalar_t, ROWS> &b,
279 unsigned int row,
unsigned int col) {
Matrix concepts.
Definition concepts.hpp:83
Scalar concept: Elements of vectors/matrices (can be simd vectors).
Definition concepts.hpp:40
constexpr double m
Meter.
Definition Units.hpp:97
Functor used to extract a block from SMatrix matrices.
Definition smatrix_getter.hpp:169
void set(input_matrix_type &m, const ROOT::Math::SVector< scalar_t, ROWS > &b, unsigned int row, unsigned int col) const
Operator setting a block with a vector.
Definition smatrix_getter.hpp:234
ROOT::Math::SVector< scalar_t, SIZE > vector(const ROOT::Math::SMatrix< scalar_t, ROWS, COLS > &m, unsigned int row, unsigned int col) const
Extract a contiguous segment from one matrix column.
Definition smatrix_getter.hpp:190
ROOT::Math::SMatrix< scalar_t, ROWS, COLS > operator()(const ROOT::Math::SMatrix< scalar_t, oROWS, oCOLS > &m, unsigned int row, unsigned int col) const
Extract a rectangular block from a matrix.
Definition smatrix_getter.hpp:177
void set(input_matrix_type &m, const ROOT::Math::SMatrix< scalar_t, ROWS, COLS > &b, std::size_t row, std::size_t col) const
Operator setting a block with a matrix.
Definition smatrix_getter.hpp:216
Functor used to access elements of SMatrix matrices.
Definition smatrix_getter.hpp:28
constexpr scalar_t & operator()(ROOT::Math::SMatrix< scalar_t, N, 1 > &m, unsigned int row) const
Access a mutable element of a single-column matrix.
Definition smatrix_getter.hpp:62
constexpr scalar_t operator()(const ROOT::Math::SVector< scalar_t, N > &m, unsigned int row) const
Read a vector element.
Definition smatrix_getter.hpp:95
constexpr scalar_t & operator()(ROOT::Math::SMatrix< scalar_t, ROWS, COLS > &m, unsigned int row, unsigned int col) const
Access a mutable matrix element.
Definition smatrix_getter.hpp:35
constexpr scalar_t operator()(const ROOT::Math::SMatrix< scalar_t, ROWS, COLS > &m, unsigned int row, unsigned int col) const
Read a matrix element.
Definition smatrix_getter.hpp:49
constexpr scalar_t operator()(const ROOT::Math::SMatrix< scalar_t, N, 1 > &m, unsigned int row) const
Read an element of a single-column matrix.
Definition smatrix_getter.hpp:73
constexpr scalar_t & operator()(ROOT::Math::SVector< scalar_t, N > &m, unsigned int row) const
Access a mutable vector element.
Definition smatrix_getter.hpp:84