ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
eigen_types.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s).
12#include "algebra/impl/detail/eigen_array.hpp"
13#include "algebra/impl/eigen_getter.hpp"
14#include "algebra/impl/eigen_transform3.hpp"
15#include "detray/algebra/concepts.hpp"
16#include "detray/algebra/type_traits.hpp"
17
18// System include(s).
19#include <cstddef>
20
21namespace detray {
22
23namespace algebra::eigen {
24
26using index_type = int;
28template <concepts::value T>
29using value_type = T;
31template <concepts::value T>
32using scalar_type = T;
34template <concepts::scalar T, index_type N>
35using storage_type = array<T, N>;
37template <concepts::scalar T, index_type N>
38using vector_type = storage_type<T, N>;
41template <concepts::scalar T, index_type ROWS, index_type COLS>
42using matrix_type =
43 Eigen::Matrix<T, ROWS, COLS, static_cast<int>(ROWS == 1), ROWS, COLS>;
44
46template <concepts::scalar T>
47using vector3 = storage_type<T, 3>;
49template <concepts::scalar T>
50using point3 = vector3<T>;
52template <concepts::scalar T>
53using vector2 = storage_type<T, 2>;
55template <concepts::scalar T>
56using point2 = vector2<T>;
57
59template <concepts::scalar T>
60using transform3 = eigen::math::transform3<T>;
61
63using element_getter = eigen::storage::element_getter;
65using block_getter = eigen::storage::block_getter;
66
67} // namespace algebra::eigen
68
69DETRAY_ALGEBRA_DEFINE_TYPE_TRAITS(algebra::eigen)
70
71// Extra specializations needed for some additional eigen types
72namespace traits {
73
76template <typename derived_t>
77struct index<Eigen::MatrixBase<derived_t>> {
79 using type = algebra::eigen::index_type;
80};
81
83template <typename T, int ROWS, int COLS, int OPT, int bROWS, int bCOLS>
84struct index<Eigen::Block<Eigen::Matrix<T, ROWS, COLS, OPT, ROWS, COLS>, bROWS,
85 bCOLS, false>> {
87 using type = algebra::eigen::index_type;
88};
89
90
94template <typename derived_t>
95struct dimensions<Eigen::MatrixBase<derived_t>> {
97 using index_type = index_t<Eigen::MatrixBase<derived_t>>;
98
100 static constexpr index_type _dim{2};
102 static constexpr index_type _rows{
103 Eigen::MatrixBase<derived_t>::RowsAtCompileTime};
104
105 static constexpr index_type _columns{
106 Eigen::MatrixBase<derived_t>::ColsAtCompileTime};
107};
108
110template <typename T, int ROWS, int COLS, int OPT, int bROWS, int bCOLS>
111struct dimensions<Eigen::Block<Eigen::Matrix<T, ROWS, COLS, OPT, ROWS, COLS>,
112 bROWS, bCOLS, false>> {
115 index_t<Eigen::Block<Eigen::Matrix<T, ROWS, COLS, OPT, ROWS, COLS>, bROWS,
116 bCOLS, false>>;
117
119 static constexpr index_type _dim{2};
121 static constexpr index_type _rows{bROWS};
123 static constexpr index_type _columns{bCOLS};
124};
125
126
129template <typename derived_t>
130struct value<Eigen::MatrixBase<derived_t>> {
132 using type = typename Eigen::MatrixBase<derived_t>::value_type;
133};
134
136template <typename T, int ROWS, int COLS, int OPT, int bROWS, int bCOLS>
137struct value<Eigen::Block<Eigen::Matrix<T, ROWS, COLS, OPT, ROWS, COLS>, bROWS,
138 bCOLS, false>> {
140 using type = T;
141};
142
143
147template <typename derived_t>
148struct vector<Eigen::MatrixBase<derived_t>> {
150 template <typename other_T, int other_N>
151 using other_type = algebra::eigen::vector_type<other_T, other_N>;
152
155 rows<Eigen::MatrixBase<derived_t>>>;
156};
157
158
162template <typename derived_t>
163struct matrix<Eigen::MatrixBase<derived_t>> {
165 template <typename other_T, int other_ROWS, int other_COLS>
166 using other_type = algebra::eigen::matrix_type<
167 typename Eigen::MatrixBase<derived_t>::value_type,
168 Eigen::MatrixBase<derived_t>::RowsAtCompileTime,
169 Eigen::MatrixBase<derived_t>::ColsAtCompileTime>;
170
172 using type = Eigen::MatrixBase<derived_t>;
173};
174
176template <typename T, int ROWS, int COLS, int OPT, int bROWS, int bCOLS>
177struct matrix<Eigen::Block<Eigen::Matrix<T, ROWS, COLS, OPT, ROWS, COLS>, bROWS,
178 bCOLS, false>> {
180 template <typename other_T, int other_ROWS, int other_COLS>
182 algebra::eigen::matrix_type<other_T, other_ROWS, other_COLS>;
183
185 using type = Eigen::Block<Eigen::Matrix<T, ROWS, COLS, OPT, ROWS, COLS>,
186 bROWS, bCOLS, false>;
187};
188
189
192template <typename derived_t>
193struct element_getter<Eigen::MatrixBase<derived_t>> {
196};
197
199template <typename T, int ROWS, int COLS, int OPT, int bROWS, int bCOLS>
200struct element_getter<Eigen::Block<
201 Eigen::Matrix<T, ROWS, COLS, OPT, ROWS, COLS>, bROWS, bCOLS, false>> {
204};
205
206
209template <typename derived_t>
210struct block_getter<Eigen::MatrixBase<derived_t>> {
213};
214
215
216} // namespace traits
217
218} // namespace detray
constexpr double T
Magnetic field, native unit (eV*s)/(e*m²).
Definition Units.hpp:168
Detray include(s).
Definition array_operators.hpp:18
Functor used to extract a block from Eigen matrices.
Definition eigen_getter.hpp:146
Functor used to access elements of Eigen matrices.
Definition eigen_getter.hpp:38
algebra::eigen::storage::block_getter type
Accessor type for Eigen matrix blocks.
Definition eigen_types.hpp:212
Definition type_traits.hpp:139
static constexpr index_type _dim
Number of matrix dimensions.
Definition eigen_types.hpp:119
index_t< Eigen::Block< Eigen::Matrix< T, ROWS, COLS, OPT, ROWS, COLS >, bROWS, bCOLS, false > > index_type
Index type used for compile-time dimensions.
Definition eigen_types.hpp:114
static constexpr index_type _columns
Block column count.
Definition eigen_types.hpp:123
index_t< Eigen::MatrixBase< derived_t > > index_type
Index type used for compile-time dimensions.
Definition eigen_types.hpp:97
static constexpr index_type _rows
Compile-time row count.
Definition eigen_types.hpp:102
static constexpr index_type _columns
Compile-time column count.
Definition eigen_types.hpp:105
static constexpr index_type _dim
Number of matrix dimensions.
Definition eigen_types.hpp:100
Matrix dimensions.
Definition type_traits.hpp:82
algebra::eigen::storage::element_getter type
Accessor type for Eigen matrix elements.
Definition eigen_types.hpp:203
algebra::eigen::storage::element_getter type
Accessor type for Eigen matrix elements.
Definition eigen_types.hpp:195
Getter types.
Definition type_traits.hpp:133
algebra::eigen::index_type type
Index type used by Eigen algebra traits.
Definition eigen_types.hpp:87
algebra::eigen::index_type type
Index type used by Eigen algebra traits.
Definition eigen_types.hpp:79
Matrix traits.
Definition type_traits.hpp:26
Eigen::Block< Eigen::Matrix< T, ROWS, COLS, OPT, ROWS, COLS >, bROWS, bCOLS, false > type
Eigen block type represented by this trait.
Definition eigen_types.hpp:185
algebra::eigen::matrix_type< other_T, other_ROWS, other_COLS > other_type
Construct an Eigen matrix type with the requested dimensions.
Definition eigen_types.hpp:181
algebra::eigen::matrix_type< typename Eigen::MatrixBase< derived_t >::value_type, Eigen::MatrixBase< derived_t >::RowsAtCompileTime, Eigen::MatrixBase< derived_t >::ColsAtCompileTime > other_type
Construct a matrix representation with the requested type and dimensions.
Definition eigen_types.hpp:166
Eigen::MatrixBase< derived_t > type
Eigen matrix expression type itself.
Definition eigen_types.hpp:172
Definition type_traits.hpp:73
typename Eigen::MatrixBase< derived_t >::value_type type
Scalar element type of the Eigen expression.
Definition eigen_types.hpp:132
Value type that is used with the matrix (e.g.
Definition type_traits.hpp:35
algebra::eigen::vector_type< other_T, other_N > other_type
Construct a vector representation with another scalar and length.
Definition eigen_types.hpp:151
other_type< value_t< Eigen::MatrixBase< derived_t > >, rows< Eigen::MatrixBase< derived_t > > > type
Vector type matching the expression's scalar type and row count.
Definition eigen_types.hpp:154
Vector type that is compatible with the matrix.
Definition type_traits.hpp:64