Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 053bc30

Browse files
committed
cleanup
1 parent ec0e35b commit 053bc30

64 files changed

Lines changed: 560 additions & 685 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ endif()
243243

244244
# Set up the Algebra Plugin libraries.
245245
add_subdirectory(common)
246-
add_subdirectory(frontend)
246+
add_subdirectory(plugins)
247247
add_subdirectory(generic)
248248
add_subdirectory(utils)
249249

common/include/algebra/concepts.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ concept transform3D = requires(T trf) {
144144
template <typename A>
145145
concept algebra = (concepts::value<typename A::value_type> &&
146146
concepts::scalar<typename A::scalar> &&
147-
concepts::index<typename A::size_type> &&
147+
concepts::index<typename A::index_type> &&
148148
concepts::vector3D<typename A::vector3D> &&
149149
concepts::point2D<typename A::point2D> &&
150150
concepts::point3D<typename A::point3D> &&

common/include/algebra/type_traits.hpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,35 +77,35 @@ using get_matrix_t = typename matrix<M>::template other_type<T, ROWS, COLS>;
7777
template <typename M>
7878
struct dimensions {
7979

80-
using size_type = int;
80+
using index_type = int;
8181

8282
// Error case
83-
static constexpr size_type dim{-1};
84-
static constexpr size_type rows{-1};
85-
static constexpr size_type columns{-1};
83+
static constexpr index_type _dim{-1};
84+
static constexpr index_type _rows{-1};
85+
static constexpr index_type _columns{-1};
8686
};
8787

8888
/// Specilization for scalar types
8989
template <typename M>
9090
requires std::is_fundamental_v<M>
9191
struct dimensions<M> {
9292

93-
using size_type = std::size_t;
93+
using index_type = std::size_t;
9494

95-
static constexpr size_type dim{0};
96-
static constexpr size_type rows{1};
97-
static constexpr size_type columns{1};
95+
static constexpr index_type _dim{0};
96+
static constexpr index_type _rows{1};
97+
static constexpr index_type _columns{1};
9898
};
9999

100100
template <class M>
101-
inline constexpr index_t<M> dim{dimensions<std::remove_cvref_t<M>>::sim};
101+
inline constexpr index_t<M> dim{dimensions<std::remove_cvref_t<M>>::_dim};
102102

103103
template <class M>
104-
inline constexpr index_t<M> rows{dimensions<std::remove_cvref_t<M>>::rows};
104+
inline constexpr index_t<M> rows{dimensions<std::remove_cvref_t<M>>::_rows};
105105

106106
template <class M>
107107
inline constexpr index_t<M> columns{
108-
dimensions<std::remove_cvref_t<M>>::columns};
108+
dimensions<std::remove_cvref_t<M>>::_columns};
109109

110110
template <class M>
111111
inline constexpr index_t<M> rank{std::min(rows<M>, columns<M>)};
@@ -114,10 +114,10 @@ template <class M>
114114
inline constexpr index_t<M> size{rows<M> * columns<M>};
115115

116116
template <class V>
117-
inline constexpr bool is_vector{dimensions<std::remove_cvref_t<V>>::dim == 1};
117+
inline constexpr bool is_vector{dimensions<std::remove_cvref_t<V>>::_dim == 1};
118118

119119
template <class M>
120-
inline constexpr bool is_matrix{dimensions<std::remove_cvref_t<M>>::dim == 2};
120+
inline constexpr bool is_matrix{dimensions<std::remove_cvref_t<M>>::_dim == 2};
121121

122122
template <class M>
123123
inline constexpr bool is_square{(rows<M> == columns<M>)};
@@ -148,7 +148,7 @@ template <typename T>
148148
struct get_algebra<T> {
149149
template <typename U>
150150
using simd = typename T::template simd<U>;
151-
using size_type = typename T::size_type;
151+
using index_type = typename T::index_type;
152152
using boolean = typename T::boolean;
153153
using value = typename T::value_type;
154154
using scalar = typename T::scalar;
@@ -173,7 +173,7 @@ template <typename A, typename T>
173173
using get_simd_t = typename traits::get_algebra<A>::template simd<T>;
174174

175175
template <typename A>
176-
using get_size_t = typename traits::get_algebra<A>::size_type;
176+
using get_size_t = typename traits::get_algebra<A>::index_type;
177177

178178
template <typename A>
179179
using get_scalar_t = typename traits::get_algebra<A>::scalar;
@@ -207,32 +207,32 @@ using get_matrix_t = typename traits::get_algebra<A>::template matrix<R, C>;
207207
\
208208
template <typename T, auto N> \
209209
struct index<A::vector_type<T, N>> { \
210-
using type = algebra::A::size_type; \
210+
using type = algebra::A::index_type; \
211211
}; \
212212
\
213213
template <typename T, auto ROWS, auto COLS> \
214214
struct index<A::matrix_type<T, ROWS, COLS>> { \
215-
using type = algebra::A::size_type; \
215+
using type = algebra::A::index_type; \
216216
}; \
217217
\
218218
template <typename T, auto N> \
219219
struct dimensions<A::vector_type<T, N>> { \
220220
\
221-
using size_type = index_t<A::vector_type<T, N>>; \
221+
using index_type = index_t<A::vector_type<T, N>>; \
222222
\
223-
static constexpr size_type dim{1}; \
224-
static constexpr size_type rows{N}; \
225-
static constexpr size_type columns{1}; \
223+
static constexpr index_type _dim{1}; \
224+
static constexpr index_type _rows{N}; \
225+
static constexpr index_type _columns{1}; \
226226
}; \
227227
\
228228
template <typename T, auto ROWS, auto COLS> \
229229
struct dimensions<A::matrix_type<T, ROWS, COLS>> { \
230230
\
231-
using size_type = index_t<A::matrix_type<T, ROWS, COLS>>; \
231+
using index_type = index_t<A::matrix_type<T, ROWS, COLS>>; \
232232
\
233-
static constexpr size_type dim{2}; \
234-
static constexpr size_type rows{ROWS}; \
235-
static constexpr size_type columns{COLS}; \
233+
static constexpr index_type _dim{2}; \
234+
static constexpr index_type _rows{ROWS}; \
235+
static constexpr index_type _columns{COLS}; \
236236
}; \
237237
\
238238
template <typename T, auto N> \

generic/include/algebra/algorithms/matrix/decomposition/partial_pivot_lud.hpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** Algebra plugins library, part of the ACTS project
22
*
3-
* (c) 2022-2024 CERN for the benefit of the ACTS project
3+
* (c) 2022-2026 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -18,24 +18,21 @@
1818
namespace algebra::generic::matrix::decomposition {
1919

2020
/// "Partial Pivot LU Decomposition", assuming a N X N matrix
21-
template <concepts::matrix matrix_t, class element_getter_t>
21+
template <concepts::matrix matrix_t>
2222
struct partial_pivot_lud {
2323

24-
using scalar_type = algebra::traits::value_t<matrix_t>;
25-
using size_type = algebra::traits::index_t<matrix_t>;
26-
using vector_type = algebra::traits::vector_t<matrix_t>;
24+
using scalar_t = algebra::traits::value_t<matrix_t>;
25+
using index_t = algebra::traits::index_t<matrix_t>;
26+
using vector_t = algebra::traits::vector_t<matrix_t>;
2727

28-
/// Function (object) used for accessing a matrix element
29-
using element_getter = element_getter_t;
30-
31-
template <size_type N>
28+
template <index_t N>
3229
struct lud {
3330
// LU decomposition matrix, equal to (L - I) + U, where the diagonal
3431
// components of L is always 1
3532
matrix_t lu;
3633

3734
// Permutation vector
38-
vector_type P;
35+
vector_t P;
3936

4037
// Number of pivots
4138
int n_pivot = 0;
@@ -44,37 +41,41 @@ struct partial_pivot_lud {
4441
ALGEBRA_HOST_DEVICE constexpr lud<algebra::traits::rank<matrix_t>> operator()(
4542
const matrix_t& m) const {
4643

47-
constexpr size_type N{algebra::traits::rank<matrix_t>};
44+
// Function (object) used for accessing a matrix element
45+
using element_getter_t = algebra::traits::element_getter_t<matrix_t>;
46+
47+
constexpr element_getter_t elem{};
48+
constexpr index_t N{algebra::traits::rank<matrix_t>};
4849

4950
// LU decomposition matrix
5051
matrix_t lu = m;
5152

5253
// Permutation
53-
vector_type P;
54+
vector_t P;
5455

5556
// Max index and value
56-
size_type max_idx;
57-
scalar_type max_val;
58-
scalar_type abs_val;
57+
index_t max_idx;
58+
scalar_t max_val;
59+
scalar_t abs_val;
5960

6061
// Number of pivoting
6162
int n_pivot = N;
6263

6364
// Rows for swapping
64-
vector_type row_0;
65-
vector_type row_1;
65+
vector_t row_0;
66+
vector_t row_1;
6667

6768
// Unit permutation matrix, P[N] initialized with N
68-
for (size_type i = 0; i < N; i++) {
69-
P[i] = static_cast<scalar_type>(i);
69+
for (index_t i = 0; i < N; i++) {
70+
P[i] = static_cast<scalar_t>(i);
7071
}
7172

72-
for (size_type i = 0; i < N; i++) {
73+
for (index_t i = 0; i < N; i++) {
7374
max_val = 0;
7475
max_idx = i;
7576

76-
for (size_type k = i; k < N; k++) {
77-
abs_val = algebra::math::fabs(element_getter()(lu, k, i));
77+
for (index_t k = i; k < N; k++) {
78+
abs_val = algebra::math::fabs(elem(lu, k, i));
7879

7980
if (abs_val > max_val) {
8081

@@ -91,27 +92,26 @@ struct partial_pivot_lud {
9192
P[max_idx] = j;
9293

9394
// Pivoting rows of A
94-
for (size_type q = 0; q < N; q++) {
95-
row_0[q] = element_getter_t()(lu, i, q);
96-
row_1[q] = element_getter_t()(lu, max_idx, q);
95+
for (index_t q = 0; q < N; q++) {
96+
row_0[q] = elem(lu, i, q);
97+
row_1[q] = elem(lu, max_idx, q);
9798
}
98-
for (size_type q = 0; q < N; q++) {
99-
element_getter_t()(lu, i, q) = row_1[q];
100-
element_getter_t()(lu, max_idx, q) = row_0[q];
99+
for (index_t q = 0; q < N; q++) {
100+
elem(lu, i, q) = row_1[q];
101+
elem(lu, max_idx, q) = row_0[q];
101102
}
102103

103104
// counting pivots starting from N (for determinant)
104105
n_pivot++;
105106
}
106107

107-
for (size_type j = i + 1; j < N; j++) {
108+
for (index_t j = i + 1; j < N; j++) {
108109
// m[j][i] /= m[i][i];
109-
element_getter_t()(lu, j, i) /= element_getter_t()(lu, i, i);
110+
elem(lu, j, i) /= elem(lu, i, i);
110111

111-
for (size_type k = i + 1; k < N; k++) {
112+
for (index_t k = i + 1; k < N; k++) {
112113
// m[j][k] -= m[j][i] * m[i][k];
113-
element_getter_t()(lu, j, k) -=
114-
element_getter_t()(lu, j, i) * element_getter_t()(lu, i, k);
114+
elem(lu, j, k) -= elem(lu, j, i) * elem(lu, i, k);
115115
}
116116
}
117117
}

generic/include/algebra/algorithms/matrix/determinant/cofactor.hpp

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** Algebra plugins library, part of the ACTS project
22
*
3-
* (c) 2022-2024 CERN for the benefit of the ACTS project
3+
* (c) 2022-2026 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -18,53 +18,63 @@
1818
namespace algebra::generic::matrix::determinant {
1919

2020
/// "Determinant getter", assuming a N X N matrix
21-
template <concepts::square_matrix matrix_t, class element_getter_t>
21+
template <concepts::square_matrix matrix_t>
2222
struct cofactor {
2323

24-
using scalar_type = algebra::traits::value_t<matrix_t>;
25-
using size_type = algebra::traits::index_t<matrix_t>;
24+
using scalar_t = algebra::traits::value_t<matrix_t>;
25+
using index_t = algebra::traits::index_t<matrix_t>;
2626

27-
/// Function (object) used for accessing a matrix element
28-
using element_getter = element_getter_t;
29-
30-
ALGEBRA_HOST_DEVICE constexpr scalar_type operator()(
31-
const matrix_t &m) const {
27+
ALGEBRA_HOST_DEVICE constexpr scalar_t operator()(const matrix_t &m) const {
3228
return determinant_getter_helper<algebra::traits::rank<matrix_t>>()(m);
3329
}
3430

35-
template <size_type N, typename Enable = void>
31+
template <index_t N>
3632
struct determinant_getter_helper;
3733

38-
template <size_type N>
39-
struct determinant_getter_helper<N, typename std::enable_if_t<N == 1>> {
34+
template <index_t N>
35+
requires(N == 1)
36+
struct determinant_getter_helper<N> {
4037
template <class input_matrix_type>
41-
ALGEBRA_HOST_DEVICE constexpr scalar_type operator()(
38+
ALGEBRA_HOST_DEVICE constexpr scalar_t operator()(
4239
const input_matrix_type &m) const {
43-
return element_getter()(m, 0, 0);
40+
41+
using element_getter_t =
42+
algebra::traits::element_getter_t<input_matrix_type>;
43+
44+
constexpr element_getter_t elem{};
45+
46+
return elem(m, 0, 0);
4447
}
4548
};
4649

47-
template <size_type N>
48-
struct determinant_getter_helper<N, typename std::enable_if_t<N != 1>> {
50+
template <index_t N>
51+
requires(N != 1)
52+
struct determinant_getter_helper<N> {
4953

5054
template <class input_matrix_type>
51-
ALGEBRA_HOST_DEVICE constexpr scalar_type operator()(
55+
ALGEBRA_HOST_DEVICE constexpr scalar_t operator()(
5256
const input_matrix_type &m) const {
5357

54-
scalar_type D = 0;
58+
using scalar_t = algebra::traits::value_t<input_matrix_type>;
59+
using index_t = algebra::traits::index_t<input_matrix_type>;
60+
using element_getter_t =
61+
algebra::traits::element_getter_t<input_matrix_type>;
62+
63+
constexpr element_getter_t elem{};
64+
65+
scalar_t D = 0;
5566

5667
// To store cofactors
57-
matrix_t temp;
68+
input_matrix_type temp;
5869

5970
// To store sign multiplier
6071
int sign = 1;
6172

6273
// Iterate for each element of first row
63-
for (size_type col = 0; col < N; col++) {
74+
for (index_t col = 0; col < N; col++) {
6475
// Getting Cofactor of A[0][f]
65-
this->get_cofactor(m, temp, size_type(0), col);
66-
D += sign * element_getter()(m, 0, col) *
67-
determinant_getter_helper<N - 1>()(temp);
76+
this->get_cofactor(m, temp, index_t(0), col);
77+
D += sign * elem(m, 0, col) * determinant_getter_helper<N - 1>()(temp);
6878

6979
// terms are to be added with alternate sign
7080
sign = -sign;
@@ -75,19 +85,26 @@ struct cofactor {
7585

7686
template <class input_matrix_type>
7787
ALGEBRA_HOST_DEVICE constexpr void get_cofactor(const input_matrix_type &m,
78-
matrix_t &temp, size_type p,
79-
size_type q) const {
88+
input_matrix_type &temp,
89+
index_t p,
90+
index_t q) const {
91+
92+
using index_t = algebra::traits::index_t<input_matrix_type>;
93+
using element_getter_t =
94+
algebra::traits::element_getter_t<input_matrix_type>;
95+
96+
constexpr element_getter_t elem{};
8097

81-
size_type i = 0;
82-
size_type j = 0;
98+
index_t i = 0;
99+
index_t j = 0;
83100

84101
// Looping for each element of the matrix
85-
for (size_type row = 0; row < N; row++) {
86-
for (size_type col = 0; col < N; col++) {
102+
for (index_t row = 0; row < N; row++) {
103+
for (index_t col = 0; col < N; col++) {
87104
// Copying into temporary matrix only those element
88105
// which are not in given row and column
89106
if (row != p && col != q) {
90-
element_getter()(temp, i, j++) = element_getter()(m, row, col);
107+
elem(temp, i, j++) = elem(m, row, col);
91108

92109
// Row is filled, so increase row index and
93110
// reset col index

0 commit comments

Comments
 (0)