From 37b8cefe5e05cfa2ad3302005f67e077481bda5f Mon Sep 17 00:00:00 2001 From: Joana Niermann Date: Wed, 4 Mar 2026 13:47:19 +0100 Subject: [PATCH] Use the detray configuration for clang-format --- .clang-format | 2 + .../include/algebra/array/data_generator.hpp | 89 +- .../include/algebra/common/benchmark_base.hpp | 131 +- .../algebra/common/benchmark_matrix.hpp | 474 ++-- .../algebra/common/benchmark_transform3.hpp | 86 +- .../algebra/common/benchmark_types.hpp | 2 +- .../algebra/common/benchmark_vector.hpp | 309 +-- .../algebra/common/register_benchmark.hpp | 12 +- .../include/algebra/eigen/data_generator.hpp | 44 +- .../include/algebra/fastor/data_generator.hpp | 48 +- .../include/algebra/vc_aos/data_generator.hpp | 86 +- .../include/algebra/vc_soa/data_generator.hpp | 119 +- benchmarks/algebra/src/benchmark_getter.cpp | 38 +- benchmarks/algebra/src/benchmark_matrix.cpp | 40 +- .../algebra/src/benchmark_transform3.cpp | 40 +- benchmarks/algebra/src/benchmark_vector.cpp | 40 +- .../algebra/src/vc_soa/vc_soa_getter.cpp | 54 +- .../algebra/src/vc_soa/vc_soa_matrix.cpp | 217 +- .../algebra/src/vc_soa/vc_soa_transform3.cpp | 66 +- .../algebra/src/vc_soa/vc_soa_vector.cpp | 60 +- common/include/algebra/array_operators.hpp | 60 +- common/include/algebra/boolean.hpp | 6 +- common/include/algebra/concepts.hpp | 38 +- common/include/algebra/matrix.hpp | 334 +-- common/include/algebra/matrix_getter.hpp | 341 +-- common/include/algebra/type_traits.hpp | 242 +- common/include/algebra/vector.hpp | 412 +-- .../decomposition/partial_pivot_lud.hpp | 160 +- .../matrix/determinant/cofactor.hpp | 156 +- .../matrix/determinant/hard_coded.hpp | 82 +- .../matrix/determinant/partial_pivot_lud.hpp | 44 +- .../algorithms/matrix/inverse/cofactor.hpp | 152 +- .../algorithms/matrix/inverse/hard_coded.hpp | 275 +- .../matrix/inverse/partial_pivot_lud.hpp | 72 +- .../algorithms/utils/algorithm_selector.hpp | 8 +- .../include/algebra/impl/generic_matrix.hpp | 359 +-- .../algebra/impl/generic_transform3.hpp | 590 ++--- .../include/algebra/impl/generic_vector.hpp | 77 +- plugins/array/include/algebra/array.hpp | 40 +- .../include/algebra/impl/array_getter.hpp | 218 +- .../include/algebra/impl/array_matrix.hpp | 36 +- .../include/algebra/impl/array_operators.hpp | 104 +- .../include/algebra/impl/array_vector.hpp | 110 +- plugins/eigen/include/algebra/eigen.hpp | 34 +- .../algebra/impl/detail/eigen_array.hpp | 6 +- .../include/algebra/impl/eigen_getter.hpp | 178 +- .../include/algebra/impl/eigen_matrix.hpp | 14 +- .../include/algebra/impl/eigen_transform3.hpp | 458 ++-- .../include/algebra/impl/eigen_types.hpp | 66 +- .../include/algebra/impl/eigen_vector.hpp | 18 +- plugins/fastor/include/algebra/fastor.hpp | 34 +- .../impl/detail/fastor_matrix_wrapper.hpp | 53 +- .../include/algebra/impl/fastor_getter.hpp | 161 +- .../include/algebra/impl/fastor_matrix.hpp | 42 +- .../algebra/impl/fastor_transform3.hpp | 426 +-- .../include/algebra/impl/fastor_vector.hpp | 108 +- .../impl/detail/smatrix_errorcheck.hpp | 17 +- .../include/algebra/impl/smatrix_getter.hpp | 176 +- .../include/algebra/impl/smatrix_matrix.hpp | 20 +- .../algebra/impl/smatrix_transform3.hpp | 479 ++-- .../include/algebra/impl/smatrix_vector.hpp | 78 +- plugins/smatrix/include/algebra/smatrix.hpp | 34 +- .../impl/vc_aos_approximately_equal.hpp | 38 +- .../include/algebra/impl/vc_aos_getter.hpp | 2 +- .../include/algebra/impl/vc_aos_matrix.hpp | 6 +- .../algebra/impl/vc_aos_transform3.hpp | 616 ++--- .../include/algebra/impl/vc_aos_types.hpp | 24 +- .../include/algebra/impl/vc_aos_vector.hpp | 63 +- plugins/vc_aos/include/algebra/vc_aos.hpp | 41 +- .../include/algebra/impl/vc_soa_boolean.hpp | 12 +- .../include/algebra/impl/vc_soa_casts.hpp | 14 +- .../include/algebra/impl/vc_soa_getter.hpp | 2 +- .../include/algebra/impl/vc_soa_math.hpp | 32 +- .../include/algebra/impl/vc_soa_matrix.hpp | 8 +- .../include/algebra/impl/vc_soa_types.hpp | 14 +- .../include/algebra/impl/vc_soa_vector.hpp | 67 +- plugins/vc_soa/include/algebra/vc_soa.hpp | 42 +- .../include/algebra/test/cpu/matrix_test.hpp | 2314 +++++++++-------- .../algebra/test/cpu/transform_test.hpp | 420 +-- .../include/algebra/test/cpu/vector_test.hpp | 422 +-- .../test/device/cuda/algebra_test_suite.cuh | 124 +- .../test/device/cuda/cuda_error_check.cpp | 12 +- .../test/device/cuda/cuda_error_check.hpp | 14 +- .../test/device/cuda/cuda_test_fixture.hpp | 12 +- .../test/device/cuda/execute_cuda_test.cuh | 39 +- .../algebra/test/device/device_fixture.hpp | 129 +- .../algebra/test/device/execute_host_test.hpp | 12 +- .../algebra/test/device/matrix_fixture.hpp | 419 +-- .../test/device/sycl/algebra_test_suite.hpp | 188 +- .../test/device/sycl/execute_sycl_test.hpp | 46 +- .../test/device/sycl/sycl_test_fixture.hpp | 18 +- .../algebra/test/device/transform_fixture.hpp | 224 +- .../algebra/test/device/vector_fixture.hpp | 236 +- .../algebra/test/framework/test_base.hpp | 16 +- .../include/algebra/test/framework/types.hpp | 34 +- tests/unit_tests/cpu/algebra/vc_soa.cpp | 720 ++--- .../algebra/utils/approximately_equal.hpp | 115 +- utils/include/algebra/utils/casts.hpp | 89 +- utils/include/algebra/utils/print.hpp | 82 +- 99 files changed, 7546 insertions(+), 7395 deletions(-) diff --git a/.clang-format b/.clang-format index 3dc2cde9..4680b245 100644 --- a/.clang-format +++ b/.clang-format @@ -1,5 +1,6 @@ --- BasedOnStyle: Google +IndentWidth: 4 Language: Cpp AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false @@ -8,4 +9,5 @@ AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false PointerAlignment: Left ColumnLimit: 80 +AccessModifierOffset: 0 KeepEmptyLinesAtTheStartOfBlocks: true diff --git a/benchmarks/algebra/include/algebra/array/data_generator.hpp b/benchmarks/algebra/include/algebra/array/data_generator.hpp index c85ad039..e9342115 100644 --- a/benchmarks/algebra/include/algebra/array/data_generator.hpp +++ b/benchmarks/algebra/include/algebra/array/data_generator.hpp @@ -22,74 +22,75 @@ namespace algebra { template inline void fill_random_vec(std::vector &collection) { - // Generate a vector of the right type with random values - std::random_device rd; - std::mt19937 mt(rd()); - std::uniform_real_distribution dist(0.f, 1.f); + // Generate a vector of the right type with random values + std::random_device rd; + std::mt19937 mt(rd()); + std::uniform_real_distribution dist(0.f, + 1.f); - auto rand_obj = [&]() { return vector_t{dist(mt), dist(mt), dist(mt)}; }; + auto rand_obj = [&]() { return vector_t{dist(mt), dist(mt), dist(mt)}; }; - collection.resize(collection.capacity()); - std::ranges::generate(collection, rand_obj); + collection.resize(collection.capacity()); + std::ranges::generate(collection, rand_obj); } /// Fill a @c std::array based transform3 with random values template inline void fill_random_trf(std::vector &collection) { - using vector_t = typename transform3_t::vector3; + using vector_t = typename transform3_t::vector3; - // Generate a random, but valid affine transformation - std::random_device rd; - std::mt19937 mt(rd()); - std::uniform_real_distribution dist(0.f, - 1.f); + // Generate a random, but valid affine transformation + std::random_device rd; + std::mt19937 mt(rd()); + std::uniform_real_distribution dist( + 0.f, 1.f); - auto rand_obj = [&]() { - vector_t x_axis; - vector_t z_axis; - vector_t t; + auto rand_obj = [&]() { + vector_t x_axis; + vector_t z_axis; + vector_t t; - x_axis = vector::normalize(vector_t{dist(mt), dist(mt), dist(mt)}); - z_axis = {dist(mt), dist(mt), dist(mt)}; - t = vector::normalize(vector_t{dist(mt), dist(mt), dist(mt)}); + x_axis = vector::normalize(vector_t{dist(mt), dist(mt), dist(mt)}); + z_axis = {dist(mt), dist(mt), dist(mt)}; + t = vector::normalize(vector_t{dist(mt), dist(mt), dist(mt)}); - // Gram-Schmidt projection - typename transform3_t::scalar_type coeff = - vector::dot(x_axis, z_axis) / vector::norm(x_axis); - z_axis = x_axis - coeff * z_axis; + // Gram-Schmidt projection + typename transform3_t::scalar_type coeff = + vector::dot(x_axis, z_axis) / vector::norm(x_axis); + z_axis = x_axis - coeff * z_axis; - return transform3_t{t, x_axis, vector::normalize(z_axis)}; - }; + return transform3_t{t, x_axis, vector::normalize(z_axis)}; + }; - collection.resize(collection.capacity()); - std::ranges::generate(collection, rand_obj); + collection.resize(collection.capacity()); + std::ranges::generate(collection, rand_obj); } /// Fill a @c std::array based matrix with random values template inline void fill_random_matrix(std::vector &collection) { - using scalar_t = typename matrix_t::value_type::value_type; + using scalar_t = typename matrix_t::value_type::value_type; - // Generate a random, but valid affine transformation - std::random_device rd; - std::mt19937 mt(rd()); - std::uniform_real_distribution dist(0.f, 1.f); - auto rand_obj = [&]() { - matrix_t m; + // Generate a random, but valid affine transformation + std::random_device rd; + std::mt19937 mt(rd()); + std::uniform_real_distribution dist(0.f, 1.f); + auto rand_obj = [&]() { + matrix_t m; - for (std::size_t j = 0u; j < m.size(); ++j) { - for (std::size_t i = 0u; i < m[0].size(); ++i) { - m[j][i] = dist(mt); - } - } + for (std::size_t j = 0u; j < m.size(); ++j) { + for (std::size_t i = 0u; i < m[0].size(); ++i) { + m[j][i] = dist(mt); + } + } - return m; - }; + return m; + }; - collection.resize(collection.capacity()); - std::ranges::generate(collection, rand_obj); + collection.resize(collection.capacity()); + std::ranges::generate(collection, rand_obj); } } // namespace algebra diff --git a/benchmarks/algebra/include/algebra/common/benchmark_base.hpp b/benchmarks/algebra/include/algebra/common/benchmark_base.hpp index 668624f6..85b429d7 100644 --- a/benchmarks/algebra/include/algebra/common/benchmark_base.hpp +++ b/benchmarks/algebra/include/algebra/common/benchmark_base.hpp @@ -18,71 +18,72 @@ namespace algebra { /// Base type for linear algebra benchmarks with google benchmark struct benchmark_base { - /// Local configuration type - struct configuration { - /// Size of data sample to be used in benchmark - std::size_t m_samples{100u}; - // Sleep after building data sample - bool m_sleep = false; - // Number of seconds to sleep - std::size_t m_n_sleep{1u}; - - /// Setters - /// @{ - configuration& n_samples(std::size_t n) { - m_samples = n; - return *this; - } - configuration& do_sleep(bool b) { - m_sleep = b; - return *this; - } - configuration& n_sleep(std::size_t n) { - m_n_sleep = n; - m_sleep = true; - return *this; - } - /// @} - - /// Getters - /// @{ - std::size_t n_samples() const { return m_samples; } - constexpr bool do_sleep() const { return m_sleep; } - constexpr std::size_t n_sleep() const { return m_n_sleep; } - /// @} - - /// Print configuration - friend std::ostream& operator<<(std::ostream& os, - const benchmark_base::configuration& cfg) { - os << " -> running:\t " << cfg.n_samples() << " samples" << std::endl; - if (cfg.do_sleep()) { - os << " -> cool down:\t " << cfg.n_sleep() << "s" << std::endl; - } - os << std::endl; - return os; - } - }; - - /// The benchmark configuration - configuration m_cfg{}; - - /// Default construction - benchmark_base() = default; - - /// Construct from an externally provided configuration @param cfg - explicit benchmark_base(configuration cfg) : m_cfg{cfg} {} - - /// @returns the benchmark configuration - configuration& config() { return m_cfg; } - - /// Default destructor - virtual ~benchmark_base() = default; - - /// @returns the benchmark name - virtual constexpr std::string name() const = 0; - - /// Benchmark case - virtual void operator()(::benchmark::State&) const = 0; + /// Local configuration type + struct configuration { + /// Size of data sample to be used in benchmark + std::size_t m_samples{100u}; + // Sleep after building data sample + bool m_sleep = false; + // Number of seconds to sleep + std::size_t m_n_sleep{1u}; + + /// Setters + /// @{ + configuration& n_samples(std::size_t n) { + m_samples = n; + return *this; + } + configuration& do_sleep(bool b) { + m_sleep = b; + return *this; + } + configuration& n_sleep(std::size_t n) { + m_n_sleep = n; + m_sleep = true; + return *this; + } + /// @} + + /// Getters + /// @{ + std::size_t n_samples() const { return m_samples; } + constexpr bool do_sleep() const { return m_sleep; } + constexpr std::size_t n_sleep() const { return m_n_sleep; } + /// @} + + /// Print configuration + friend std::ostream& operator<<( + std::ostream& os, const benchmark_base::configuration& cfg) { + os << " -> running:\t " << cfg.n_samples() << " samples" + << std::endl; + if (cfg.do_sleep()) { + os << " -> cool down:\t " << cfg.n_sleep() << "s" << std::endl; + } + os << std::endl; + return os; + } + }; + + /// The benchmark configuration + configuration m_cfg{}; + + /// Default construction + benchmark_base() = default; + + /// Construct from an externally provided configuration @param cfg + explicit benchmark_base(configuration cfg) : m_cfg{cfg} {} + + /// @returns the benchmark configuration + configuration& config() { return m_cfg; } + + /// Default destructor + virtual ~benchmark_base() = default; + + /// @returns the benchmark name + virtual constexpr std::string name() const = 0; + + /// Benchmark case + virtual void operator()(::benchmark::State&) const = 0; }; } // namespace algebra diff --git a/benchmarks/algebra/include/algebra/common/benchmark_matrix.hpp b/benchmarks/algebra/include/algebra/common/benchmark_matrix.hpp index 9489727e..fc60d8b4 100644 --- a/benchmarks/algebra/include/algebra/common/benchmark_matrix.hpp +++ b/benchmarks/algebra/include/algebra/common/benchmark_matrix.hpp @@ -28,313 +28,323 @@ void fill_random_vec(std::vector&); template struct matrix_bm : public benchmark_base { - /// Prefix for the benchmark name - static constexpr std::string_view name{"matrix"}; + /// Prefix for the benchmark name + static constexpr std::string_view name{"matrix"}; - std::vector a; - std::vector b; + std::vector a; + std::vector b; - /// No default construction: Cannot prepare data - matrix_bm() = delete; + /// No default construction: Cannot prepare data + matrix_bm() = delete; - /// Construct from an externally provided configuration @param cfg - explicit matrix_bm(benchmark_base::configuration cfg) : benchmark_base{cfg} { + /// Construct from an externally provided configuration @param cfg + explicit matrix_bm(benchmark_base::configuration cfg) + : benchmark_base{cfg} { - const std::size_t n_data{this->m_cfg.n_samples()}; + const std::size_t n_data{this->m_cfg.n_samples()}; - a.reserve(n_data); - b.reserve(n_data); + a.reserve(n_data); + b.reserve(n_data); - fill_random_matrix(a); - fill_random_matrix(b); - } + fill_random_matrix(a); + fill_random_matrix(b); + } - matrix_bm(const matrix_bm& bm) = default; - matrix_bm& operator=(matrix_bm& other) = default; + matrix_bm(const matrix_bm& bm) = default; + matrix_bm& operator=(matrix_bm& other) = default; - /// Clear state - ~matrix_bm() override { - a.clear(); - b.clear(); - } + /// Clear state + ~matrix_bm() override { + a.clear(); + b.clear(); + } }; /// Benchmark operations on a single matrix (transpose, inverse etc) template - requires std::invocable + requires std::invocable struct matrix_unaryOP_bm : public matrix_bm { - using base_type = matrix_bm; + using base_type = matrix_bm; - matrix_unaryOP_bm() = delete; - explicit matrix_unaryOP_bm(benchmark_base::configuration cfg) - : base_type{cfg} {} - matrix_unaryOP_bm(const matrix_unaryOP_bm& bm) = default; - matrix_unaryOP_bm& operator=(matrix_unaryOP_bm& other) = default; + matrix_unaryOP_bm() = delete; + explicit matrix_unaryOP_bm(benchmark_base::configuration cfg) + : base_type{cfg} {} + matrix_unaryOP_bm(const matrix_unaryOP_bm& bm) = default; + matrix_unaryOP_bm& operator=(matrix_unaryOP_bm& other) = default; - constexpr std::string name() const override { - return std::string{base_type::name} + "_" + std::string{unaryOP::name}; - } + constexpr std::string name() const override { + return std::string{base_type::name} + "_" + std::string{unaryOP::name}; + } - inline void operator()(::benchmark::State& state) const override { + inline void operator()(::benchmark::State& state) const override { - using result_t = std::invoke_result_t; + using result_t = std::invoke_result_t; - const std::size_t n_samples{this->m_cfg.n_samples()}; + const std::size_t n_samples{this->m_cfg.n_samples()}; - // Run the benchmark - for (auto _ : state) { - for (std::size_t i{0}; i < n_samples; ++i) { - result_t result = unaryOP{}(this->a[i]); - ::benchmark::DoNotOptimize(result); - } + // Run the benchmark + for (auto _ : state) { + for (std::size_t i{0}; i < n_samples; ++i) { + result_t result = unaryOP{}(this->a[i]); + ::benchmark::DoNotOptimize(result); + } + } } - } }; /// Benchmark elementwise addition/subtraction/multiplication of matrices template - requires std::invocable + requires std::invocable struct matrix_binaryOP_bm : public matrix_bm { - using base_type = matrix_bm; + using base_type = matrix_bm; - matrix_binaryOP_bm() = delete; - explicit matrix_binaryOP_bm(benchmark_base::configuration cfg) - : base_type{cfg} {} - matrix_binaryOP_bm(const matrix_binaryOP_bm& bm) = default; - matrix_binaryOP_bm& operator=(matrix_binaryOP_bm& other) = default; + matrix_binaryOP_bm() = delete; + explicit matrix_binaryOP_bm(benchmark_base::configuration cfg) + : base_type{cfg} {} + matrix_binaryOP_bm(const matrix_binaryOP_bm& bm) = default; + matrix_binaryOP_bm& operator=(matrix_binaryOP_bm& other) = default; - constexpr std::string name() const override { - return std::string{base_type::name} + "_" + std::string{binaryOP::name}; - } + constexpr std::string name() const override { + return std::string{base_type::name} + "_" + std::string{binaryOP::name}; + } - inline void operator()(::benchmark::State& state) const override { + inline void operator()(::benchmark::State& state) const override { - using result_t = std::invoke_result_t; + using result_t = std::invoke_result_t; - const std::size_t n_samples{this->m_cfg.n_samples()}; + const std::size_t n_samples{this->m_cfg.n_samples()}; - // Run the benchmark - for (auto _ : state) { - for (std::size_t i{0}; i < n_samples; ++i) { - result_t result = binaryOP{}(this->a[i], this->b[i]); - ::benchmark::DoNotOptimize(result); - } + // Run the benchmark + for (auto _ : state) { + for (std::size_t i{0}; i < n_samples; ++i) { + result_t result = binaryOP{}(this->a[i], this->b[i]); + ::benchmark::DoNotOptimize(result); + } + } } - } }; /// Benchmark matrix vector multiplication template struct matrix_vector_bm : public matrix_bm { - using base_type = matrix_bm; + using base_type = matrix_bm; - std::vector v; + std::vector v; - matrix_vector_bm() = delete; - explicit matrix_vector_bm(benchmark_base::configuration cfg) - : base_type{cfg} { + matrix_vector_bm() = delete; + explicit matrix_vector_bm(benchmark_base::configuration cfg) + : base_type{cfg} { - v.reserve(this->m_cfg.n_samples()); + v.reserve(this->m_cfg.n_samples()); - fill_random_vec(v); - } - matrix_vector_bm(const matrix_vector_bm& bm) = default; - matrix_vector_bm& operator=(matrix_vector_bm& other) = default; + fill_random_vec(v); + } + matrix_vector_bm(const matrix_vector_bm& bm) = default; + matrix_vector_bm& operator=(matrix_vector_bm& other) = default; - /// Clear state - ~matrix_vector_bm() override { v.clear(); } + /// Clear state + ~matrix_vector_bm() override { v.clear(); } - constexpr std::string name() const override { - return std::string{base_type::name} + "_vector"; - } + constexpr std::string name() const override { + return std::string{base_type::name} + "_vector"; + } - inline void operator()(::benchmark::State& state) const override { + inline void operator()(::benchmark::State& state) const override { - const std::size_t n_samples{this->m_cfg.n_samples()}; + const std::size_t n_samples{this->m_cfg.n_samples()}; - // Run the benchmark - for (auto _ : state) { - for (std::size_t i{0}; i < n_samples; ++i) { - vector_t result = this->a[i] * this->v[i]; - ::benchmark::DoNotOptimize(result); - } + // Run the benchmark + for (auto _ : state) { + for (std::size_t i{0}; i < n_samples; ++i) { + vector_t result = this->a[i] * this->v[i]; + ::benchmark::DoNotOptimize(result); + } + } } - } }; // Functions to be benchmarked namespace bench_op::matrix { struct add { - static constexpr std::string_view name{"add"}; - template - constexpr matrix_t operator()(const matrix_t& a, const matrix_t& b) const { - return a + b; - } + static constexpr std::string_view name{"add"}; + template + constexpr matrix_t operator()(const matrix_t& a, const matrix_t& b) const { + return a + b; + } }; struct sub { - static constexpr std::string_view name{"sub"}; - template - constexpr matrix_t operator()(const matrix_t& a, const matrix_t& b) const { - return a - b; - } + static constexpr std::string_view name{"sub"}; + template + constexpr matrix_t operator()(const matrix_t& a, const matrix_t& b) const { + return a - b; + } }; struct mul { - static constexpr std::string_view name{"mul"}; - template - constexpr matrix_t operator()(const matrix_t& a, const matrix_t& b) const { - return a * b; - } + static constexpr std::string_view name{"mul"}; + template + constexpr matrix_t operator()(const matrix_t& a, const matrix_t& b) const { + return a * b; + } }; struct transpose { - static constexpr std::string_view name{"transpose"}; - template - constexpr auto operator()(const matrix_t& a) const { - return algebra::matrix::transpose(a); - } + static constexpr std::string_view name{"transpose"}; + template + constexpr auto operator()(const matrix_t& a) const { + return algebra::matrix::transpose(a); + } }; struct determinant { - static constexpr std::string_view name{"determinant"}; - template - constexpr auto operator()(const matrix_t& a) const { - return algebra::matrix::determinant(a); - } + static constexpr std::string_view name{"determinant"}; + template + constexpr auto operator()(const matrix_t& a) const { + return algebra::matrix::determinant(a); + } }; struct invert { - static constexpr std::string_view name{"invert"}; - template - constexpr auto operator()(const matrix_t& a) const { - return algebra::matrix::inverse(a); - } + static constexpr std::string_view name{"invert"}; + template + constexpr auto operator()(const matrix_t& a) const { + return algebra::matrix::inverse(a); + } }; } // namespace bench_op::matrix // Macro for defining all matrix benchmark types #define ALGEBRA_PLUGINS_DEFINE_MATRIX_BENCH(PLUGIN) \ - using mat44_transp_f_t = matrix_unaryOP_bm, \ - bench_op::matrix::transpose>; \ - using mat44_transp_d_t = \ - matrix_unaryOP_bm, \ - bench_op::matrix::transpose>; \ - using mat66_transp_f_t = matrix_unaryOP_bm, \ - bench_op::matrix::transpose>; \ - using mat66_transp_d_t = \ - matrix_unaryOP_bm, \ - bench_op::matrix::transpose>; \ - using mat88_transp_f_t = matrix_unaryOP_bm, \ - bench_op::matrix::transpose>; \ - using mat88_transp_d_t = \ - matrix_unaryOP_bm, \ - bench_op::matrix::transpose>; \ + using mat44_transp_f_t = \ + matrix_unaryOP_bm, \ + bench_op::matrix::transpose>; \ + using mat44_transp_d_t = \ + matrix_unaryOP_bm, \ + bench_op::matrix::transpose>; \ + using mat66_transp_f_t = \ + matrix_unaryOP_bm, \ + bench_op::matrix::transpose>; \ + using mat66_transp_d_t = \ + matrix_unaryOP_bm, \ + bench_op::matrix::transpose>; \ + using mat88_transp_f_t = \ + matrix_unaryOP_bm, \ + bench_op::matrix::transpose>; \ + using mat88_transp_d_t = \ + matrix_unaryOP_bm, \ + bench_op::matrix::transpose>; \ \ - using mat44_inv_f_t = matrix_unaryOP_bm, \ - bench_op::matrix::invert>; \ - using mat44_inv_d_t = matrix_unaryOP_bm, \ - bench_op::matrix::invert>; \ - using mat66_inv_f_t = matrix_unaryOP_bm, \ - bench_op::matrix::invert>; \ - using mat66_inv_d_t = matrix_unaryOP_bm, \ - bench_op::matrix::invert>; \ - using mat88_inv_f_t = matrix_unaryOP_bm, \ - bench_op::matrix::invert>; \ - using mat88_inv_d_t = matrix_unaryOP_bm, \ - bench_op::matrix::invert>; \ + using mat44_inv_f_t = matrix_unaryOP_bm, \ + bench_op::matrix::invert>; \ + using mat44_inv_d_t = matrix_unaryOP_bm, \ + bench_op::matrix::invert>; \ + using mat66_inv_f_t = matrix_unaryOP_bm, \ + bench_op::matrix::invert>; \ + using mat66_inv_d_t = matrix_unaryOP_bm, \ + bench_op::matrix::invert>; \ + using mat88_inv_f_t = matrix_unaryOP_bm, \ + bench_op::matrix::invert>; \ + using mat88_inv_d_t = matrix_unaryOP_bm, \ + bench_op::matrix::invert>; \ \ - using mat44_det_f_t = matrix_unaryOP_bm, \ - bench_op::matrix::determinant>; \ - using mat44_det_d_t = matrix_unaryOP_bm, \ - bench_op::matrix::determinant>; \ - using mat66_det_f_t = matrix_unaryOP_bm, \ - bench_op::matrix::determinant>; \ - using mat66_det_d_t = matrix_unaryOP_bm, \ - bench_op::matrix::determinant>; \ - using mat88_det_f_t = matrix_unaryOP_bm, \ - bench_op::matrix::determinant>; \ - using mat88_det_d_t = matrix_unaryOP_bm, \ - bench_op::matrix::determinant>; \ + using mat44_det_f_t = matrix_unaryOP_bm, \ + bench_op::matrix::determinant>; \ + using mat44_det_d_t = matrix_unaryOP_bm, \ + bench_op::matrix::determinant>; \ + using mat66_det_f_t = matrix_unaryOP_bm, \ + bench_op::matrix::determinant>; \ + using mat66_det_d_t = matrix_unaryOP_bm, \ + bench_op::matrix::determinant>; \ + using mat88_det_f_t = matrix_unaryOP_bm, \ + bench_op::matrix::determinant>; \ + using mat88_det_d_t = matrix_unaryOP_bm, \ + bench_op::matrix::determinant>; \ \ - using mat44_add_f_t = matrix_binaryOP_bm, \ - bench_op::matrix::add>; \ - using mat44_add_d_t = matrix_binaryOP_bm, \ - bench_op::matrix::add>; \ - using mat66_add_f_t = matrix_binaryOP_bm, \ - bench_op::matrix::add>; \ - using mat66_add_d_t = matrix_binaryOP_bm, \ - bench_op::matrix::add>; \ - using mat88_add_f_t = matrix_binaryOP_bm, \ - bench_op::matrix::add>; \ - using mat88_add_d_t = matrix_binaryOP_bm, \ - bench_op::matrix::add>; \ + using mat44_add_f_t = matrix_binaryOP_bm, \ + bench_op::matrix::add>; \ + using mat44_add_d_t = \ + matrix_binaryOP_bm, \ + bench_op::matrix::add>; \ + using mat66_add_f_t = matrix_binaryOP_bm, \ + bench_op::matrix::add>; \ + using mat66_add_d_t = \ + matrix_binaryOP_bm, \ + bench_op::matrix::add>; \ + using mat88_add_f_t = matrix_binaryOP_bm, \ + bench_op::matrix::add>; \ + using mat88_add_d_t = \ + matrix_binaryOP_bm, \ + bench_op::matrix::add>; \ \ - using mat44_mul_f_t = matrix_binaryOP_bm, \ - bench_op::matrix::mul>; \ - using mat44_mul_d_t = matrix_binaryOP_bm, \ - bench_op::matrix::mul>; \ - using mat66_mul_f_t = matrix_binaryOP_bm, \ - bench_op::matrix::mul>; \ - using mat66_mul_d_t = matrix_binaryOP_bm, \ - bench_op::matrix::mul>; \ - using mat88_mul_f_t = matrix_binaryOP_bm, \ - bench_op::matrix::mul>; \ - using mat88_mul_d_t = matrix_binaryOP_bm, \ - bench_op::matrix::mul>; \ + using mat44_mul_f_t = matrix_binaryOP_bm, \ + bench_op::matrix::mul>; \ + using mat44_mul_d_t = \ + matrix_binaryOP_bm, \ + bench_op::matrix::mul>; \ + using mat66_mul_f_t = matrix_binaryOP_bm, \ + bench_op::matrix::mul>; \ + using mat66_mul_d_t = \ + matrix_binaryOP_bm, \ + bench_op::matrix::mul>; \ + using mat88_mul_f_t = matrix_binaryOP_bm, \ + bench_op::matrix::mul>; \ + using mat88_mul_d_t = \ + matrix_binaryOP_bm, \ + bench_op::matrix::mul>; \ \ - using mat44_vec_f_t = matrix_vector_bm, \ - PLUGIN::vector_type>; \ - using mat44_vec_d_t = matrix_vector_bm, \ - PLUGIN::vector_type>; \ - using mat66_vec_f_t = matrix_vector_bm, \ - PLUGIN::vector_type>; \ - using mat66_vec_d_t = matrix_vector_bm, \ - PLUGIN::vector_type>; \ - using mat88_vec_f_t = matrix_vector_bm, \ - PLUGIN::vector_type>; \ - using mat88_vec_d_t = matrix_vector_bm, \ - PLUGIN::vector_type>; + using mat44_vec_f_t = matrix_vector_bm, \ + PLUGIN::vector_type>; \ + using mat44_vec_d_t = matrix_vector_bm, \ + PLUGIN::vector_type>; \ + using mat66_vec_f_t = matrix_vector_bm, \ + PLUGIN::vector_type>; \ + using mat66_vec_d_t = matrix_vector_bm, \ + PLUGIN::vector_type>; \ + using mat88_vec_f_t = matrix_vector_bm, \ + PLUGIN::vector_type>; \ + using mat88_vec_d_t = matrix_vector_bm, \ + PLUGIN::vector_type>; // Macro for registering all matrix benchmarks -#define ALGEBRA_PLUGINS_REGISTER_MATRIX_BENCH(CFGS, CFGD) \ - algebra::register_benchmark(CFGS, "_4x4_single"); \ - algebra::register_benchmark(CFGD, "_4x4_double"); \ - algebra::register_benchmark(CFGS, "_6x6_single"); \ - algebra::register_benchmark(CFGD, "_6x6_double"); \ - algebra::register_benchmark(CFGS, "_8x8_single"); \ - algebra::register_benchmark(CFGD, "_8x8_double"); \ - \ - algebra::register_benchmark(CFGS, "_4x4_single"); \ - algebra::register_benchmark(CFGD, "_4x4_double"); \ - algebra::register_benchmark(CFGS, "_6x6_single"); \ - algebra::register_benchmark(CFGD, "_6x6_double"); \ - algebra::register_benchmark(CFGS, "_8x8_single"); \ - algebra::register_benchmark(CFGD, "_8x8_double"); \ - \ - algebra::register_benchmark(CFGS, "_4x4_single"); \ - algebra::register_benchmark(CFGD, "_4x4_double"); \ - algebra::register_benchmark(CFGS, "_6x6_single"); \ - algebra::register_benchmark(CFGD, "_6x6_double"); \ - algebra::register_benchmark(CFGS, "_8x8_single"); \ - algebra::register_benchmark(CFGD, "_8x8_double"); \ - \ - algebra::register_benchmark(CFGS, "_4x4_single"); \ - algebra::register_benchmark(CFGD, "_4x4_double"); \ - algebra::register_benchmark(CFGS, "_6x6_single"); \ - algebra::register_benchmark(CFGD, "_6x6_double"); \ - algebra::register_benchmark(CFGS, "_8x8_single"); \ - algebra::register_benchmark(CFGD, "_8x8_double"); \ - \ - algebra::register_benchmark(CFGS, "_4x4_single"); \ - algebra::register_benchmark(CFGD, "_4x4_double"); \ - algebra::register_benchmark(CFGS, "_6x6_single"); \ - algebra::register_benchmark(CFGD, "_6x6_double"); \ - algebra::register_benchmark(CFGS, "_8x8_single"); \ - algebra::register_benchmark(CFGD, "_8x8_double"); \ - \ - algebra::register_benchmark(CFGS, "_4x4_single"); \ - algebra::register_benchmark(CFGD, "_4x4_double"); \ - algebra::register_benchmark(CFGS, "_6x6_single"); \ - algebra::register_benchmark(CFGD, "_6x6_double"); \ - algebra::register_benchmark(CFGS, "_8x8_single"); \ - algebra::register_benchmark(CFGD, "_8x8_double"); +#define ALGEBRA_PLUGINS_REGISTER_MATRIX_BENCH(CFGS, CFGD) \ + algebra::register_benchmark(CFGS, "_4x4_single"); \ + algebra::register_benchmark(CFGD, "_4x4_double"); \ + algebra::register_benchmark(CFGS, "_6x6_single"); \ + algebra::register_benchmark(CFGD, "_6x6_double"); \ + algebra::register_benchmark(CFGS, "_8x8_single"); \ + algebra::register_benchmark(CFGD, "_8x8_double"); \ + \ + algebra::register_benchmark(CFGS, "_4x4_single"); \ + algebra::register_benchmark(CFGD, "_4x4_double"); \ + algebra::register_benchmark(CFGS, "_6x6_single"); \ + algebra::register_benchmark(CFGD, "_6x6_double"); \ + algebra::register_benchmark(CFGS, "_8x8_single"); \ + algebra::register_benchmark(CFGD, "_8x8_double"); \ + \ + algebra::register_benchmark(CFGS, "_4x4_single"); \ + algebra::register_benchmark(CFGD, "_4x4_double"); \ + algebra::register_benchmark(CFGS, "_6x6_single"); \ + algebra::register_benchmark(CFGD, "_6x6_double"); \ + algebra::register_benchmark(CFGS, "_8x8_single"); \ + algebra::register_benchmark(CFGD, "_8x8_double"); \ + \ + algebra::register_benchmark(CFGS, "_4x4_single"); \ + algebra::register_benchmark(CFGD, "_4x4_double"); \ + algebra::register_benchmark(CFGS, "_6x6_single"); \ + algebra::register_benchmark(CFGD, "_6x6_double"); \ + algebra::register_benchmark(CFGS, "_8x8_single"); \ + algebra::register_benchmark(CFGD, "_8x8_double"); \ + \ + algebra::register_benchmark(CFGS, "_4x4_single"); \ + algebra::register_benchmark(CFGD, "_4x4_double"); \ + algebra::register_benchmark(CFGS, "_6x6_single"); \ + algebra::register_benchmark(CFGD, "_6x6_double"); \ + algebra::register_benchmark(CFGS, "_8x8_single"); \ + algebra::register_benchmark(CFGD, "_8x8_double"); \ + \ + algebra::register_benchmark(CFGS, "_4x4_single"); \ + algebra::register_benchmark(CFGD, "_4x4_double"); \ + algebra::register_benchmark(CFGS, "_6x6_single"); \ + algebra::register_benchmark(CFGD, "_6x6_double"); \ + algebra::register_benchmark(CFGS, "_8x8_single"); \ + algebra::register_benchmark(CFGD, "_8x8_double"); } // namespace algebra diff --git a/benchmarks/algebra/include/algebra/common/benchmark_transform3.hpp b/benchmarks/algebra/include/algebra/common/benchmark_transform3.hpp index 17b62c7b..c44e2e3b 100644 --- a/benchmarks/algebra/include/algebra/common/benchmark_transform3.hpp +++ b/benchmarks/algebra/include/algebra/common/benchmark_transform3.hpp @@ -26,68 +26,68 @@ void fill_random_trf(std::vector&); /// Benchmark for vector operations template struct transform3_bm : public vector_bm { - private: - using base_type = vector_bm; + private: + using base_type = vector_bm; - public: - /// Prefix for the benchmark name - static constexpr std::string_view bm_name{"transform3"}; + public: + /// Prefix for the benchmark name + static constexpr std::string_view bm_name{"transform3"}; - std::vector trfs; + std::vector trfs; - /// No default construction: Cannot prepare data - transform3_bm() = delete; - /// Construct from an externally provided configuration @param cfg - explicit transform3_bm(benchmark_base::configuration cfg) : base_type{cfg} { + /// No default construction: Cannot prepare data + transform3_bm() = delete; + /// Construct from an externally provided configuration @param cfg + explicit transform3_bm(benchmark_base::configuration cfg) : base_type{cfg} { - trfs.reserve(this->m_cfg.n_samples()); + trfs.reserve(this->m_cfg.n_samples()); - fill_random_trf(trfs); - } - transform3_bm(const transform3_bm& bm) = default; - transform3_bm& operator=(transform3_bm& other) = default; + fill_random_trf(trfs); + } + transform3_bm(const transform3_bm& bm) = default; + transform3_bm& operator=(transform3_bm& other) = default; - /// Clear state - ~transform3_bm() override { trfs.clear(); } + /// Clear state + ~transform3_bm() override { trfs.clear(); } - constexpr std::string name() const override { - return std::string{base_type::name} + "_" + std::string{bm_name}; - } + constexpr std::string name() const override { + return std::string{base_type::name} + "_" + std::string{bm_name}; + } - /// Benchmark case - inline void operator()(::benchmark::State& state) const override { + /// Benchmark case + inline void operator()(::benchmark::State& state) const override { - using vector_t = typename transform3_t::vector3; - using point_t = typename transform3_t::point3; + using vector_t = typename transform3_t::vector3; + using point_t = typename transform3_t::point3; - const std::size_t n_samples{this->m_cfg.n_samples()}; + const std::size_t n_samples{this->m_cfg.n_samples()}; - // Run the benchmark - for (auto _ : state) { - for (std::size_t i{0}; i < n_samples; ++i) { + // Run the benchmark + for (auto _ : state) { + for (std::size_t i{0}; i < n_samples; ++i) { - point_t result1 = this->trfs[i].point_to_global(this->a[i]); - point_t result2 = this->trfs[i].point_to_local(this->a[i]); - vector_t result3 = this->trfs[i].vector_to_global(this->a[i]); - vector_t result4 = this->trfs[i].vector_to_local(this->a[i]); + point_t result1 = this->trfs[i].point_to_global(this->a[i]); + point_t result2 = this->trfs[i].point_to_local(this->a[i]); + vector_t result3 = this->trfs[i].vector_to_global(this->a[i]); + vector_t result4 = this->trfs[i].vector_to_local(this->a[i]); - ::benchmark::DoNotOptimize(result1); - ::benchmark::DoNotOptimize(result2); - ::benchmark::DoNotOptimize(result3); - ::benchmark::DoNotOptimize(result4); - } + ::benchmark::DoNotOptimize(result1); + ::benchmark::DoNotOptimize(result2); + ::benchmark::DoNotOptimize(result3); + ::benchmark::DoNotOptimize(result4); + } + } } - } }; // Macro for defining all transform benchmark types -#define ALGEBRA_PLUGINS_DEFINE_TRANSFORM_BENCH(PLUGIN) \ - using trf_f_t = transform3_bm>; \ - using trf_d_t = transform3_bm>; +#define ALGEBRA_PLUGINS_DEFINE_TRANSFORM_BENCH(PLUGIN) \ + using trf_f_t = transform3_bm>; \ + using trf_d_t = transform3_bm>; // Macro for registering all transform benchmarks #define ALGEBRA_PLUGINS_REGISTER_TRANSFORM_BENCH(CFGS, CFGD) \ - algebra::register_benchmark(CFGS, "_single"); \ - algebra::register_benchmark(CFGD, "_double"); + algebra::register_benchmark(CFGS, "_single"); \ + algebra::register_benchmark(CFGD, "_double"); } // namespace algebra diff --git a/benchmarks/algebra/include/algebra/common/benchmark_types.hpp b/benchmarks/algebra/include/algebra/common/benchmark_types.hpp index e95ed197..afcffb89 100644 --- a/benchmarks/algebra/include/algebra/common/benchmark_types.hpp +++ b/benchmarks/algebra/include/algebra/common/benchmark_types.hpp @@ -42,7 +42,7 @@ namespace algebra::benchmark { #define ALGEBRA_DEFINE_BENCHMARK_NAME(ALGEBRA) \ - static std::string plugin_name(#ALGEBRA); + static std::string plugin_name(#ALGEBRA); // Select algebra-plugin to compile the test with #if ALGEBRA_BENCHMARK_ARRAY diff --git a/benchmarks/algebra/include/algebra/common/benchmark_vector.hpp b/benchmarks/algebra/include/algebra/common/benchmark_vector.hpp index 0164e9de..02ab77e3 100644 --- a/benchmarks/algebra/include/algebra/common/benchmark_vector.hpp +++ b/benchmarks/algebra/include/algebra/common/benchmark_vector.hpp @@ -28,146 +28,147 @@ void fill_random_vec(std::vector &); template struct vector_bm : public benchmark_base { - /// Prefix for the benchmark name - static constexpr std::string_view name{"vector"}; + /// Prefix for the benchmark name + static constexpr std::string_view name{"vector"}; - std::vector a; - std::vector b; - std::vector results; + std::vector a; + std::vector b; + std::vector results; - /// No default construction: Cannot prepare data - vector_bm() = delete; + /// No default construction: Cannot prepare data + vector_bm() = delete; - /// Construct from an externally provided configuration @param cfg - explicit vector_bm(benchmark_base::configuration cfg) : benchmark_base{cfg} { + /// Construct from an externally provided configuration @param cfg + explicit vector_bm(benchmark_base::configuration cfg) + : benchmark_base{cfg} { - const std::size_t n_data{this->m_cfg.n_samples()}; + const std::size_t n_data{this->m_cfg.n_samples()}; - a.reserve(n_data); - b.reserve(n_data); + a.reserve(n_data); + b.reserve(n_data); - fill_random_vec(a); - fill_random_vec(b); - } - vector_bm(const vector_bm &bm) = default; - vector_bm &operator=(vector_bm &other) = default; + fill_random_vec(a); + fill_random_vec(b); + } + vector_bm(const vector_bm &bm) = default; + vector_bm &operator=(vector_bm &other) = default; - /// Clear state - ~vector_bm() override { - a.clear(); - b.clear(); - } + /// Clear state + ~vector_bm() override { + a.clear(); + b.clear(); + } }; /// Benchmark elementwise addition of vectors template