From bf37559e762623c8aa584590998f48a51419521a Mon Sep 17 00:00:00 2001 From: Joana Niermann <53186085+niermann999@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:14:56 +0000 Subject: [PATCH] Intorduce concepts (#132) This PR adds concepts for the main linear algebra types and constrains as many template parameters as possible. Also switches out the std::enable_if instances against requires clauses --- .../benchmark/array/data_generator.hpp | 7 +- .../benchmark/common/benchmark_matrix.hpp | 26 +-- .../benchmark/common/benchmark_transform3.hpp | 4 +- .../benchmark/common/benchmark_vector.hpp | 25 ++- .../benchmark/common/register_benchmark.hpp | 8 +- .../benchmark/eigen/data_generator.hpp | 6 +- .../benchmark/vc_aos/data_generator.hpp | 6 +- .../benchmark/vc_soa/data_generator.hpp | 15 +- common/include/algebra/concepts.hpp | 107 ++++++++++ common/include/algebra/type_traits.hpp | 31 ++- .../include/algebra/array_cmath.hpp | 22 +- .../include/algebra/eigen_eigen.hpp | 2 +- .../include/algebra/eigen_generic.hpp | 2 +- .../include/algebra/fastor_fastor.hpp | 2 +- .../include/algebra/smatrix_generic.hpp | 2 +- frontend/vc_aos/include/algebra/vc_aos.hpp | 2 +- .../include/algebra/vc_aos_generic.hpp | 2 +- frontend/vc_soa/include/algebra/vc_soa.hpp | 2 +- .../include/algebra/vecmem_cmath.hpp | 22 +- .../algebra/math/impl/cmath_matrix.hpp | 12 +- .../algebra/math/impl/cmath_operators.hpp | 164 +++++---------- .../algebra/math/impl/cmath_vector.hpp | 36 ++-- math/common/include/algebra/math/common.hpp | 15 +- .../algebra/math/impl/eigen_matrix.hpp | 4 +- .../algebra/math/impl/eigen_transform3.hpp | 79 ++++---- .../algebra/math/impl/fastor_matrix.hpp | 20 +- .../algebra/math/impl/fastor_transform3.hpp | 2 +- .../algebra/math/impl/fastor_vector.hpp | 26 +-- .../decomposition/partial_pivot_lud.hpp | 13 +- .../matrix/determinant/cofactor.hpp | 9 +- .../matrix/determinant/hard_coded.hpp | 13 +- .../matrix/determinant/partial_pivot_lud.hpp | 12 +- .../algorithms/matrix/inverse/cofactor.hpp | 15 +- .../algorithms/matrix/inverse/hard_coded.hpp | 13 +- .../matrix/inverse/partial_pivot_lud.hpp | 9 +- .../algorithms/utils/algorithm_finder.hpp | 26 +-- .../algebra/math/impl/generic_matrix.hpp | 69 +++---- .../algebra/math/impl/generic_transform3.hpp | 11 +- .../algebra/math/impl/generic_vector.hpp | 77 ++++--- .../algebra/math/impl/smatrix_matrix.hpp | 46 ++--- .../algebra/math/impl/smatrix_transform3.hpp | 2 +- .../algebra/math/impl/smatrix_vector.hpp | 54 ++--- .../algebra/math/impl/vc_aos_matrix.hpp | 5 +- .../algebra/math/impl/vc_aos_transform3.hpp | 40 ++-- .../algebra/math/impl/vc_aos_vector.hpp | 19 +- .../algebra/math/impl/vc_soa_matrix.hpp | 5 +- .../algebra/math/impl/vc_soa_vector.hpp | 79 ++++---- .../array/include/algebra/storage/array.hpp | 13 +- .../algebra/storage/impl/cmath_getter.hpp | 50 ++--- .../algebra/storage/array_operators.hpp | 33 ++- .../common/include/algebra/storage/matrix.hpp | 152 +++++++------- .../include/algebra/storage/matrix_getter.hpp | 97 ++++----- .../common/include/algebra/storage/vector.hpp | 191 +++++++++--------- .../eigen/include/algebra/storage/eigen.hpp | 19 +- .../algebra/storage/impl/eigen_array.hpp | 7 +- .../algebra/storage/impl/eigen_getter.hpp | 93 +++++---- .../fastor/include/algebra/storage/fastor.hpp | 15 +- .../algebra/storage/impl/fastor_getter.hpp | 40 ++-- .../algebra/storage/impl/fastor_matrix.hpp | 13 +- .../algebra/storage/impl/smatrix_getter.hpp | 42 ++-- .../include/algebra/storage/smatrix.hpp | 15 +- .../algebra/storage/impl/vc_aos_getter.hpp | 6 +- .../vc_aos/include/algebra/storage/vc_aos.hpp | 54 +++-- .../algebra/storage/impl/vc_soa_getter.hpp | 6 +- .../vc_soa/include/algebra/storage/vc_soa.hpp | 56 +++-- .../vecmem/include/algebra/storage/vecmem.hpp | 13 +- tests/common/test_base.hpp | 12 +- tests/common/test_host_basics.hpp | 79 ++++++-- tests/common/test_types.hpp | 14 +- tests/vc_soa/vc_soa.cpp | 158 +++++++-------- 70 files changed, 1271 insertions(+), 1075 deletions(-) create mode 100644 common/include/algebra/concepts.hpp diff --git a/benchmarks/array/include/benchmark/array/data_generator.hpp b/benchmarks/array/include/benchmark/array/data_generator.hpp index b4bf5939..bfbfd847 100644 --- a/benchmarks/array/include/benchmark/array/data_generator.hpp +++ b/benchmarks/array/include/benchmark/array/data_generator.hpp @@ -9,6 +9,7 @@ // Project include(s) #include "algebra/array_cmath.hpp" +#include "algebra/concepts.hpp" // System include(s) #include @@ -18,7 +19,7 @@ namespace algebra { /// Fill an @c std::array based vector with random values -template +template inline void fill_random_vec(std::vector &collection) { // Generate a vector of the right type with random values @@ -33,7 +34,7 @@ inline void fill_random_vec(std::vector &collection) { } /// Fill a @c std::array based transform3 with random values -template +template inline void fill_random_trf(std::vector &collection) { using vector_t = typename transform3_t::vector3; @@ -64,7 +65,7 @@ inline void fill_random_trf(std::vector &collection) { } /// Fill a @c std::array based matrix with random values -template +template inline void fill_random_matrix(std::vector &collection) { using scalar_t = typename matrix_t::value_type::value_type; diff --git a/benchmarks/common/include/benchmark/common/benchmark_matrix.hpp b/benchmarks/common/include/benchmark/common/benchmark_matrix.hpp index e17ce107..a99ef315 100644 --- a/benchmarks/common/include/benchmark/common/benchmark_matrix.hpp +++ b/benchmarks/common/include/benchmark/common/benchmark_matrix.hpp @@ -17,14 +17,14 @@ namespace algebra { -template +template void fill_random_matrix(std::vector&); -template +template void fill_random_vec(std::vector&); /// Benchmark for matrix operations -template +template struct matrix_bm : public benchmark_base { /// Prefix for the benchmark name @@ -59,8 +59,9 @@ struct matrix_bm : public benchmark_base { }; /// Benchmark operations on a single matrix (transpose, inverse etc) -template -struct matrix_unaryOP_bm : public matrix_bm { +template +requires std::invocable struct matrix_unaryOP_bm + : public matrix_bm { using base_type = matrix_bm; matrix_unaryOP_bm() = delete; @@ -90,8 +91,9 @@ struct matrix_unaryOP_bm : public matrix_bm { }; /// Benchmark elementwise addition/subtraction/multiplication of matrices -template -struct matrix_binaryOP_bm : public matrix_bm { +template +requires std::invocable struct matrix_binaryOP_bm + : public matrix_bm { using base_type = matrix_bm; matrix_binaryOP_bm() = delete; @@ -121,7 +123,7 @@ struct matrix_binaryOP_bm : public matrix_bm { }; /// Benchmark matrix vector multiplication -template +template struct matrix_vector_bm : public matrix_bm { using base_type = matrix_bm; @@ -162,21 +164,21 @@ namespace bench_op { struct add { inline static const std::string name{"add"}; - template + template matrix_t operator()(const matrix_t& a, const matrix_t& b) const { return a + b; } }; struct sub { inline static const std::string name{"sub"}; - template + template matrix_t operator()(const matrix_t& a, const matrix_t& b) const { return a - b; } }; struct mul { inline static const std::string name{"mul"}; - template + template matrix_t operator()(const matrix_t& a, const matrix_t& b) const { return a * b; } @@ -184,7 +186,7 @@ struct mul { struct transpose { inline static const std::string name{"transpose"}; - template + template auto operator()(const matrix_t& a) const { return algebra::matrix::transpose(a); } diff --git a/benchmarks/common/include/benchmark/common/benchmark_transform3.hpp b/benchmarks/common/include/benchmark/common/benchmark_transform3.hpp index 1c0e84d3..0442b987 100644 --- a/benchmarks/common/include/benchmark/common/benchmark_transform3.hpp +++ b/benchmarks/common/include/benchmark/common/benchmark_transform3.hpp @@ -19,11 +19,11 @@ namespace algebra { -template +template void fill_random_trf(std::vector&); /// Benchmark for vector operations -template +template struct transform3_bm : public vector_bm { private: using base_type = vector_bm; diff --git a/benchmarks/common/include/benchmark/common/benchmark_vector.hpp b/benchmarks/common/include/benchmark/common/benchmark_vector.hpp index 9d672055..a49f3a1c 100644 --- a/benchmarks/common/include/benchmark/common/benchmark_vector.hpp +++ b/benchmarks/common/include/benchmark/common/benchmark_vector.hpp @@ -20,11 +20,11 @@ namespace algebra { -template +template void fill_random_vec(std::vector &); /// Benchmark for vector operations -template +template struct vector_bm : public benchmark_base { /// Prefix for the benchmark name @@ -57,9 +57,10 @@ struct vector_bm : public benchmark_base { }; /// Benchmark elementwise addition of vectors -template