diff --git a/benchmarks/common/include/benchmark/common/benchmark_getter.hpp b/benchmarks/common/include/benchmark/common/benchmark_getter.hpp index 30db7232..c6c9c9ae 100644 --- a/benchmarks/common/include/benchmark/common/benchmark_getter.hpp +++ b/benchmarks/common/include/benchmark/common/benchmark_getter.hpp @@ -11,4 +11,5 @@ #include "benchmark_vector.hpp" #include "register_benchmark.hpp" -namespace algebra::bench_op {} // namespace algebra::bench_op +namespace algebra::bench_op { /* TODO: Implement */ +} // namespace algebra::bench_op diff --git a/common/include/algebra/type_traits.hpp b/common/include/algebra/type_traits.hpp index 53adf683..5eac0c3e 100644 --- a/common/include/algebra/type_traits.hpp +++ b/common/include/algebra/type_traits.hpp @@ -61,7 +61,7 @@ template struct matrix {}; template ROWS, index_t COLS, typename T> -using other_matrix_t = typename matrix::template other_type; +using get_matrix_t = typename matrix::template other_type; /// @} /// Matrix dimensions @@ -71,8 +71,7 @@ struct dimensions {}; /// Specilization for scalar types template - requires std::is_fundamental_v -struct dimensions { +requires std::is_fundamental_v struct dimensions { using size_type = std::size_t; @@ -121,6 +120,101 @@ template using block_getter_t = typename block_getter::type; /// @} -/// @} - } // namespace algebra::trait + +/// Default type trait specializations +/// @{ +#define ALGEBRA_PLUGINS_DEFINE_TYPE_TRAITS(A) \ + \ + namespace trait { \ + \ + template \ + struct index> { \ + using type = algebra::A::size_type; \ + }; \ + \ + template \ + struct index> { \ + using type = algebra::A::size_type; \ + }; \ + \ + template \ + struct dimensions> { \ + \ + using size_type = index_t>; \ + \ + static constexpr size_type dim{1}; \ + static constexpr size_type rows{N}; \ + static constexpr size_type columns{1}; \ + }; \ + \ + template \ + struct dimensions> { \ + \ + using size_type = index_t>; \ + \ + static constexpr size_type dim{2}; \ + static constexpr size_type rows{ROWS}; \ + static constexpr size_type columns{COLS}; \ + }; \ + \ + template \ + struct value> { \ + using type = T; \ + }; \ + \ + template \ + struct value> { \ + using type = T; \ + }; \ + \ + template \ + struct vector> { \ + \ + template \ + using other_type = A::vector_type; \ + \ + using type = other_type; \ + }; \ + \ + template \ + struct vector> { \ + \ + template \ + using other_type = A::vector_type; \ + \ + using type = other_type; \ + }; \ + \ + template \ + struct matrix> { \ + template \ + using other_type = A::matrix_type; \ + \ + using type = A::matrix_type; \ + }; \ + \ + template \ + struct matrix> { \ + template \ + using other_type = A::matrix_type; \ + \ + using type = other_type; \ + }; \ + \ + template \ + struct element_getter> { \ + using type = A::element_getter; \ + }; \ + \ + template \ + struct element_getter> { \ + using type = A::element_getter; \ + }; \ + \ + template \ + struct block_getter> { \ + using type = A::block_getter; \ + }; \ + \ + } // namespace algebra::trait diff --git a/math/cmath/include/algebra/math/impl/cmath_matrix.hpp b/math/cmath/include/algebra/math/impl/cmath_matrix.hpp index a5df35f4..67ea5317 100644 --- a/math/cmath/include/algebra/math/impl/cmath_matrix.hpp +++ b/math/cmath/include/algebra/math/impl/cmath_matrix.hpp @@ -37,7 +37,7 @@ requires(std::is_scalar_v) /// Set @param m as zero matrix template class array_t> -ALGEBRA_HOST_DEVICE inline constexpr void set_zero( +ALGEBRA_HOST_DEVICE constexpr void set_zero( array_t, COLS> &m) { m = zero, COLS>>(); } @@ -45,7 +45,7 @@ ALGEBRA_HOST_DEVICE inline constexpr void set_zero( /// Set @param m as identity matrix template class array_t> -ALGEBRA_HOST_DEVICE inline constexpr void set_identity( +ALGEBRA_HOST_DEVICE constexpr void set_identity( array_t, COLS> &m) { m = identity, COLS>>(); } diff --git a/math/cmath/include/algebra/math/impl/cmath_vector.hpp b/math/cmath/include/algebra/math/impl/cmath_vector.hpp index 12a6866e..a4aad3e6 100644 --- a/math/cmath/include/algebra/math/impl/cmath_vector.hpp +++ b/math/cmath/include/algebra/math/impl/cmath_vector.hpp @@ -20,10 +20,9 @@ namespace algebra::cmath { /// /// @return the scalar dot product value template class array_t, - typename scalar_t, size_type N, - std::enable_if_t, bool> = true> -ALGEBRA_HOST_DEVICE inline scalar_t dot(const array_t &a, - const array_t &b) { + typename scalar_t, size_type N> +requires std::is_scalar_v ALGEBRA_HOST_DEVICE inline scalar_t dot( + const array_t &a, const array_t &b) { array_t tmp; for (size_type i = 0; i < N; i++) { tmp[i] = a[i] * b[i]; @@ -41,13 +40,11 @@ ALGEBRA_HOST_DEVICE inline scalar_t dot(const array_t &a, /// @param b the second input matrix with single column /// /// @return the scalar dot product value -template < - typename size_type, template class array_t, - typename scalar_t, size_type N, size_type COLS, - std::enable_if_t, bool> = true> -ALGEBRA_HOST_DEVICE inline scalar_t dot( - const array_t &a, - const array_t, COLS> &b) { +template class array_t, + typename scalar_t, size_type N, size_type COLS> +requires(COLS == 1 && std::is_scalar_v) ALGEBRA_HOST_DEVICE + inline scalar_t dot(const array_t &a, + const array_t, COLS> &b) { array_t tmp; for (size_type i = 0; i < N; i++) { tmp[i] = a[i] * b[0][i]; @@ -65,13 +62,11 @@ ALGEBRA_HOST_DEVICE inline scalar_t dot( /// @param b the second input vector /// /// @return the scalar dot product value -template < - typename size_type, template class array_t, - typename scalar_t, size_type N, size_type COLS, - std::enable_if_t, bool> = true> -ALGEBRA_HOST_DEVICE inline scalar_t dot( - const array_t, COLS> &a, - const array_t &b) { +template class array_t, + typename scalar_t, size_type N, size_type COLS> +requires(COLS == 1 && std::is_scalar_v) ALGEBRA_HOST_DEVICE + inline scalar_t dot(const array_t, COLS> &a, + const array_t &b) { array_t tmp; for (size_type i = 0; i < N; i++) { tmp[i] = a[0][i] * b[i]; @@ -89,13 +84,11 @@ ALGEBRA_HOST_DEVICE inline scalar_t dot( /// @param b the second input matrix with single column /// /// @return the scalar dot product value -template < - typename size_type, template class array_t, - typename scalar_t, size_type N, size_type COLS, - std::enable_if_t, bool> = true> -ALGEBRA_HOST_DEVICE inline scalar_t dot( - const array_t, COLS> &a, - const array_t, COLS> &b) { +template class array_t, + typename scalar_t, size_type N, size_type COLS> +requires(COLS == 1 && std::is_scalar_v) ALGEBRA_HOST_DEVICE + inline scalar_t dot(const array_t, COLS> &a, + const array_t, COLS> &b) { array_t tmp; for (size_type i = 0; i < N; i++) { tmp[i] = a[0][i] * b[0][i]; @@ -111,9 +104,9 @@ ALGEBRA_HOST_DEVICE inline scalar_t dot( /// /// @param v the input vector template class array_t, - typename scalar_t, size_type N, - std::enable_if_t<(N >= 2) && std::is_scalar_v, bool> = true> -ALGEBRA_HOST_DEVICE inline scalar_t norm(const array_t &v) { + typename scalar_t, size_type N> +requires(N >= 2 && std::is_scalar_v) ALGEBRA_HOST_DEVICE + inline scalar_t norm(const array_t &v) { return algebra::math::sqrt(dot(v, v)); } @@ -123,10 +116,9 @@ ALGEBRA_HOST_DEVICE inline scalar_t norm(const array_t &v) { /// /// @param v the input vector template class array_t, - typename scalar_t, size_type N, - std::enable_if_t<(N >= 3) && std::is_scalar_v, bool> = true> -ALGEBRA_HOST_DEVICE inline scalar_t eta( - const array_t &v) noexcept { + typename scalar_t, size_type N> +requires(N >= 3 && std::is_scalar_v) ALGEBRA_HOST_DEVICE + inline scalar_t eta(const array_t &v) noexcept { return algebra::math::atanh(v[2] / norm(v)); } @@ -135,10 +127,10 @@ ALGEBRA_HOST_DEVICE inline scalar_t eta( /// /// @param v the input vector template class array_t, - typename scalar_t, size_type N, - std::enable_if_t, bool> = true> -ALGEBRA_HOST_DEVICE inline array_t normalize( - const array_t &v) { + typename scalar_t, size_type N> +requires std::is_scalar_v + ALGEBRA_HOST_DEVICE inline array_t normalize( + const array_t &v) { return (static_cast(1.) / norm(v)) * v; } diff --git a/math/eigen/include/algebra/math/impl/eigen_vector.hpp b/math/eigen/include/algebra/math/impl/eigen_vector.hpp index bf8cbd41..3486cf81 100644 --- a/math/eigen/include/algebra/math/impl/eigen_vector.hpp +++ b/math/eigen/include/algebra/math/impl/eigen_vector.hpp @@ -41,12 +41,10 @@ ALGEBRA_HOST_DEVICE inline auto norm(const Eigen::MatrixBase &v) { /// rows >= 3 /// /// @param v the input vector -template < - typename derived_type, - std::enable_if_t::RowsAtCompileTime >= 3, - bool> = true> -ALGEBRA_HOST_DEVICE inline auto eta( - const Eigen::MatrixBase &v) noexcept { +template +requires(Eigen::MatrixBase::RowsAtCompileTime >= + 3) ALGEBRA_HOST_DEVICE + inline auto eta(const Eigen::MatrixBase &v) noexcept { return algebra::math::atanh(v[2] / v.norm()); } diff --git a/math/fastor/include/algebra/math/impl/fastor_vector.hpp b/math/fastor/include/algebra/math/impl/fastor_vector.hpp index b6f4df2c..08c2d603 100644 --- a/math/fastor/include/algebra/math/impl/fastor_vector.hpp +++ b/math/fastor/include/algebra/math/impl/fastor_vector.hpp @@ -24,9 +24,9 @@ namespace algebra::fastor::math { /// This method retrieves theta from a vector, vector base with rows >= 3 /// /// @param v the input vector -template = 3, bool> = true> -ALGEBRA_HOST inline scalar_t theta( - const Fastor::Tensor &v) noexcept { +template +requires(N >= 3) ALGEBRA_HOST inline scalar_t + theta(const Fastor::Tensor &v) noexcept { return algebra::math::atan2(Fastor::norm(v(Fastor::fseq<0, 2>())), v[2]); } @@ -34,9 +34,9 @@ ALGEBRA_HOST inline scalar_t theta( /// This method retrieves the perpenticular magnitude of a vector with rows >= 2 /// /// @param v the input vector -template = 2, bool> = true> -ALGEBRA_HOST inline scalar_t perp( - const Fastor::Tensor &v) noexcept { +template +requires(N >= 2) ALGEBRA_HOST inline scalar_t + perp(const Fastor::Tensor &v) noexcept { return algebra::math::sqrt( Fastor::inner(v(Fastor::fseq<0, 2>()), v(Fastor::fseq<0, 2>()))); @@ -55,9 +55,9 @@ ALGEBRA_HOST inline scalar_t norm(const Fastor::Tensor &v) { /// rows >= 3 /// /// @param v the input vector -template = 3, bool> = true> -ALGEBRA_HOST inline scalar_t eta( - const Fastor::Tensor &v) noexcept { +template +requires(N >= 3) ALGEBRA_HOST inline scalar_t + eta(const Fastor::Tensor &v) noexcept { return algebra::math::atanh(v[2] / Fastor::norm(v)); } diff --git a/math/generic/include/algebra/math/impl/generic_matrix.hpp b/math/generic/include/algebra/math/impl/generic_matrix.hpp index c460e820..41c49864 100644 --- a/math/generic/include/algebra/math/impl/generic_matrix.hpp +++ b/math/generic/include/algebra/math/impl/generic_matrix.hpp @@ -71,7 +71,7 @@ ALGEBRA_HOST_DEVICE inline auto transpose(const matrix_t &m) { constexpr index_t rows{algebra::trait::rows}; constexpr index_t columns{algebra::trait::columns}; - algebra::trait::other_matrix_t ret; + algebra::trait::get_matrix_t ret; for (index_t i = 0; i < rows; ++i) { for (index_t j = 0; j < columns; ++j) { diff --git a/math/generic/include/algebra/math/impl/generic_transform3.hpp b/math/generic/include/algebra/math/impl/generic_transform3.hpp index 3b14fd82..ee740e3b 100644 --- a/math/generic/include/algebra/math/impl/generic_transform3.hpp +++ b/math/generic/include/algebra/math/impl/generic_transform3.hpp @@ -138,9 +138,7 @@ struct transform3 { /// /// @param m is the full 4x4 matrix ALGEBRA_HOST_DEVICE - explicit transform3(const matrix44 &m) { - - _data = m; + explicit transform3(const matrix44 &m) : _data{m} { _data_inv = matrix_inversion{}(_data); } diff --git a/math/generic/include/algebra/math/impl/generic_vector.hpp b/math/generic/include/algebra/math/impl/generic_vector.hpp index 7261ec54..51256f95 100644 --- a/math/generic/include/algebra/math/impl/generic_vector.hpp +++ b/math/generic/include/algebra/math/impl/generic_vector.hpp @@ -17,10 +17,10 @@ namespace algebra::generic::math { /// This method retrieves phi from a vector with rows >= 2 /// /// @param v the input vector -template , bool> = true> -ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t phi( - const vector_t &v) noexcept { +template +requires algebra::trait::is_vector + ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t phi( + const vector_t &v) noexcept { using element_getter_t = algebra::trait::element_getter_t; @@ -31,10 +31,10 @@ ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t phi( /// This method retrieves the perpendicular magnitude of a vector with rows >= 2 /// /// @param v the input vector -template , bool> = true> -ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t perp( - const vector_t &v) noexcept { +template +requires algebra::trait::is_vector + ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t perp( + const vector_t &v) noexcept { using element_getter_t = algebra::trait::element_getter_t; @@ -46,10 +46,10 @@ ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t perp( /// This method retrieves theta from a vector with rows >= 3 /// /// @param v the input vector -template , bool> = true> -ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t theta( - const vector_t &v) noexcept { +template +requires algebra::trait::is_vector + ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t theta( + const vector_t &v) noexcept { using element_getter_t = algebra::trait::element_getter_t; @@ -65,12 +65,11 @@ ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t theta( /// @param b the second input vector /// /// @return a vector representing the cross product -template == 1 && - algebra::trait::columns == 1), - bool> = true> -ALGEBRA_HOST_DEVICE inline algebra::trait::vector_t cross( - const vector1_t &a, const vector2_t &b) { +template +requires(algebra::trait::columns == 1 && + algebra::trait::columns == 1) ALGEBRA_HOST_DEVICE + inline algebra::trait::vector_t cross(const vector1_t &a, + const vector2_t &b) { using element_getter_t = algebra::trait::element_getter_t; @@ -92,12 +91,11 @@ ALGEBRA_HOST_DEVICE inline algebra::trait::vector_t cross( /// @param b the second input vector /// /// @return the scalar dot product value -template == 1 && - algebra::trait::columns == 1), - bool> = true> -ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t dot( - const vector1_t &a, const vector2_t &b) { +template +requires(algebra::trait::columns == 1 && + algebra::trait::columns == 1) ALGEBRA_HOST_DEVICE + inline algebra::trait::scalar_t dot(const vector1_t &a, + const vector2_t &b) { using scalar_t = algebra::trait::scalar_t; using index_t = algebra::trait::index_t; @@ -115,10 +113,10 @@ ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t dot( /// This method retrieves the norm of a vector with rows >= 3 /// /// @param v the input vector -template , bool> = true> -ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t norm( - const vector_t &v) { +template +requires algebra::trait::is_vector + ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t norm( + const vector_t &v) { return algebra::math::sqrt(dot(v, v)); } @@ -127,10 +125,10 @@ ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t norm( /// rows >= 3 /// /// @param v the input vector -template , bool> = true> -ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t eta( - const vector_t &v) noexcept { +template +requires algebra::trait::is_vector + ALGEBRA_HOST_DEVICE inline algebra::trait::scalar_t eta( + const vector_t &v) noexcept { using element_getter_t = algebra::trait::element_getter_t; diff --git a/math/smatrix/include/algebra/math/impl/smatrix_vector.hpp b/math/smatrix/include/algebra/math/impl/smatrix_vector.hpp index 7989fc52..bb5fca1d 100644 --- a/math/smatrix/include/algebra/math/impl/smatrix_vector.hpp +++ b/math/smatrix/include/algebra/math/impl/smatrix_vector.hpp @@ -21,17 +21,16 @@ namespace algebra::smatrix::math { /// This method retrieves phi from a vector, vector base with rows >= 2 /// /// @param v the input vector -template = 2, bool> = true> -ALGEBRA_HOST inline scalar_t phi( - const ROOT::Math::SVector &v) noexcept { +template +requires(N >= 2) ALGEBRA_HOST inline scalar_t + phi(const ROOT::Math::SVector &v) noexcept { return static_cast(TMath::ATan2(v[1], v[0])); } -template = 2, bool> = true> -ALGEBRA_HOST inline scalar_t phi( - const ROOT::Math::VecExpr &v) noexcept { +template +requires(N >= 2) ALGEBRA_HOST inline scalar_t + phi(const ROOT::Math::VecExpr &v) noexcept { return static_cast(TMath::ATan2(v.apply(1), v.apply(0))); } @@ -39,18 +38,17 @@ ALGEBRA_HOST inline scalar_t phi( /// This method retrieves theta from a vector, vector base with rows >= 3 /// /// @param v the input vector -template = 3, bool> = true> -ALGEBRA_HOST inline scalar_t theta( - const ROOT::Math::SVector &v) noexcept { +template +requires(N >= 3) ALGEBRA_HOST inline scalar_t + theta(const ROOT::Math::SVector &v) noexcept { return static_cast( TMath::ATan2(TMath::Sqrt(v[0] * v[0] + v[1] * v[1]), v[2])); } -template = 3, bool> = true> -ALGEBRA_HOST inline scalar_t theta( - const ROOT::Math::VecExpr &v) noexcept { +template +requires(N >= 3) ALGEBRA_HOST inline scalar_t + theta(const ROOT::Math::VecExpr &v) noexcept { return static_cast(TMath::ATan2( TMath::Sqrt(v.apply(0) * v.apply(0) + v.apply(1) * v.apply(1)), @@ -77,17 +75,16 @@ ALGEBRA_HOST inline scalar_t norm( /// rows >= 3 /// /// @param v the input vector -template = 3, bool> = true> -ALGEBRA_HOST inline scalar_t eta( - const ROOT::Math::SVector &v) noexcept { +template +requires(N >= 3) ALGEBRA_HOST inline scalar_t + eta(const ROOT::Math::SVector &v) noexcept { return static_cast(TMath::ATanH(v[2] / norm(v))); } -template = 3, bool> = true> -ALGEBRA_HOST inline scalar_t eta( - const ROOT::Math::VecExpr &v) noexcept { +template +requires(N >= 3) ALGEBRA_HOST inline scalar_t + eta(const ROOT::Math::VecExpr &v) noexcept { return static_cast(TMath::ATanH(v.apply(2) / norm(v))); } @@ -95,17 +92,16 @@ ALGEBRA_HOST inline scalar_t eta( /// This method retrieves the perpendicular magnitude of a vector with rows >= 2 /// /// @param v the input vector -template = 2, bool> = true> -ALGEBRA_HOST inline scalar_t perp( - const ROOT::Math::SVector &v) noexcept { +template +requires(N >= 2) ALGEBRA_HOST inline scalar_t + perp(const ROOT::Math::SVector &v) noexcept { return static_cast(TMath::Sqrt(v[0] * v[0] + v[1] * v[1])); } -template = 2, bool> = true> -ALGEBRA_HOST inline scalar_t perp( - const ROOT::Math::VecExpr &v) noexcept { +template +requires(N >= 2) ALGEBRA_HOST inline scalar_t + perp(const ROOT::Math::VecExpr &v) noexcept { return static_cast( TMath::Sqrt(v.apply(0) * v.apply(0) + v.apply(1) * v.apply(1))); diff --git a/math/smatrix/include/algebra/math/smatrix.hpp b/math/smatrix/include/algebra/math/smatrix.hpp index 418bb931..e55507f4 100644 --- a/math/smatrix/include/algebra/math/smatrix.hpp +++ b/math/smatrix/include/algebra/math/smatrix.hpp @@ -8,7 +8,6 @@ #pragma once // Project include(s). -#include "algebra/math/impl/smatrix_getter.hpp" #include "algebra/math/impl/smatrix_matrix.hpp" #include "algebra/math/impl/smatrix_transform3.hpp" #include "algebra/math/impl/smatrix_vector.hpp" diff --git a/math/vc_soa/include/algebra/math/impl/vc_soa_vector.hpp b/math/vc_soa/include/algebra/math/impl/vc_soa_vector.hpp index e8473f75..07fdf65c 100644 --- a/math/vc_soa/include/algebra/math/impl/vc_soa_vector.hpp +++ b/math/vc_soa/include/algebra/math/impl/vc_soa_vector.hpp @@ -30,9 +30,8 @@ namespace algebra::vc_soa::math { /// /// @param v the input vector template class array_t, - std::enable_if_t= 2, bool> = true> -ALGEBRA_HOST_DEVICE inline auto phi( + template class array_t> +requires(N >= 2) ALGEBRA_HOST_DEVICE inline auto phi( const storage::vector, array_t> &v) { return Vc::atan2(v[1], v[0]); @@ -46,9 +45,8 @@ ALGEBRA_HOST_DEVICE inline auto phi( /// /// @param v the input vector template class array_t, - std::enable_if_t= 2, bool> = true> -ALGEBRA_HOST_DEVICE inline auto perp( + template class array_t> +requires(N >= 2) ALGEBRA_HOST_DEVICE inline auto perp( const storage::vector, array_t> &v) { return Vc::sqrt(Vc::fma(v[0], v[0], v[1] * v[1])); @@ -62,9 +60,8 @@ ALGEBRA_HOST_DEVICE inline auto perp( /// /// @param v the input vector template class array_t, - std::enable_if_t= 3, bool> = true> -ALGEBRA_HOST_DEVICE inline auto theta( + template class array_t> +requires(N >= 3) ALGEBRA_HOST_DEVICE inline auto theta( const storage::vector, array_t> &v) { return Vc::atan2(perp(v), v[2]); @@ -81,11 +78,11 @@ ALGEBRA_HOST_DEVICE inline auto theta( /// /// @return a vector (expression) representing the cross product template class array_t, - std::enable_if_t = true> -ALGEBRA_HOST_DEVICE inline storage::vector, array_t> -cross(const storage::vector, array_t> &a, - const storage::vector, array_t> &b) { + template class array_t> +requires(N == 3) ALGEBRA_HOST_DEVICE + inline storage::vector, array_t> cross( + const storage::vector, array_t> &a, + const storage::vector, array_t> &b) { return {Vc::fma(a[1], b[2], -b[1] * a[2]), Vc::fma(a[2], b[0], -b[2] * a[0]), Vc::fma(a[0], b[1], -b[0] * a[1])}; @@ -161,9 +158,8 @@ normalize(const storage::vector, array_t> &v) { /// /// @param v the input vector template class array_t, - std::enable_if_t= 3, bool> = true> -ALGEBRA_HOST_DEVICE inline auto eta( + template class array_t> +requires(N >= 3) ALGEBRA_HOST_DEVICE inline auto eta( const storage::vector, array_t> &v) { // atanh does not exist in Vc diff --git a/storage/array/include/algebra/storage/array.hpp b/storage/array/include/algebra/storage/array.hpp index 49226ecf..ed79c674 100644 --- a/storage/array/include/algebra/storage/array.hpp +++ b/storage/array/include/algebra/storage/array.hpp @@ -44,120 +44,13 @@ using vector2 = storage_type; template using point2 = vector2; -} // namespace array - -namespace trait { - -/// Type trait specializations -/// @{ - -/// Index -/// @{ -template -struct index> { - using type = algebra::array::size_type; -}; - -template -struct index, COLS>> { - using type = algebra::array::size_type; -}; -/// @} - -/// Dimension -/// @{ -template -struct dimensions> { - - using size_type = index_t>; - - static constexpr size_type dim{1}; - static constexpr size_type rows{N}; - static constexpr size_type columns{1}; -}; - -template -struct dimensions, COLS>> { - - using size_type = index_t, COLS>>; - - static constexpr size_type dim{2}; - static constexpr size_type rows{ROWS}; - static constexpr size_type columns{COLS}; -}; -/// @} - -/// Value -/// @{ -template -struct value> { - using type = T; -}; - -template -struct value, COLS>> { - using type = T; -}; -/// @} +/// Element Getter +using element_getter = cmath::storage::element_getter; +/// Block Getter +using block_getter = cmath::storage::block_getter; -/// Vector -/// @{ -template -struct vector> { - - template - using other_type = std::array; - - using type = other_type; -}; - -template -struct vector, COLS>> { - - template - using other_type = std::array; - - using type = other_type; -}; -/// @} - -/// Matrix -/// @{ -template -struct matrix, COLS>> { - template - using other_type = std::array, other_COLS>; - - using type = std::array, COLS>; -}; - -template -struct matrix> { - template - using other_type = std::array, other_COLS>; - - using type = other_type; -}; -/// @} - -/// Elemet/Block Getter -/// @{ -template -struct element_getter> { - using type = cmath::storage::element_getter; -}; - -template -struct element_getter, COLS>> { - using type = cmath::storage::element_getter; -}; - -template -struct block_getter, COLS>> { - using type = cmath::storage::block_getter; -}; -/// @} +} // namespace array -} // namespace trait +ALGEBRA_PLUGINS_DEFINE_TYPE_TRAITS(array) } // namespace algebra diff --git a/storage/common/include/algebra/storage/matrix.hpp b/storage/common/include/algebra/storage/matrix.hpp index 58db1629..721d5a1d 100644 --- a/storage/common/include/algebra/storage/matrix.hpp +++ b/storage/common/include/algebra/storage/matrix.hpp @@ -31,8 +31,8 @@ struct alignas(alignof(storage::vector)) matrix { /// Construct from given column vectors @param v template - requires(sizeof...(vector_t) == COL) - explicit matrix(vector_t &&...v) : m_storage{std::forward(v)...} {} + requires(sizeof...(vector_t) == COL) explicit matrix(vector_t &&... v) + : m_storage{std::forward(v)...} {} /// Equality operator between two matrices template )) matrix { /// @{ // AoS template - requires(!std::is_scalar_v) - constexpr bool equal(const matrix &rhs, std::index_sequence) const { + requires(!std::is_scalar_v) constexpr bool equal( + const matrix &rhs, std::index_sequence) const { return (... && (m_storage[I] == rhs[I])); } // SoA template - requires(std::is_scalar_v) - constexpr bool equal(const matrix &rhs, std::index_sequence) const { + requires(std::is_scalar_v) constexpr bool equal( + const matrix &rhs, std::index_sequence) const { return (... && ((m_storage[I].get() == rhs[I].get()).isFull())); } /// @} @@ -96,15 +96,16 @@ struct alignas(alignof(storage::vector)) matrix { template class A> - requires(std::is_scalar_v || std::is_same_v) - ALGEBRA_HOST_DEVICE friend constexpr decltype(auto) operator*( - scalar_t a, const matrix &rhs) noexcept; + requires(std::is_scalar_v || + std::is_same_v) ALGEBRA_HOST_DEVICE + friend constexpr decltype(auto) + operator*(scalar_t a, const matrix &rhs) noexcept; template class A> - requires(std::is_scalar_v || std::is_same_v) - friend constexpr decltype(auto) operator*(const matrix &lhs, - scalar_t a) noexcept; + requires(std::is_scalar_v || + std::is_same_v) friend constexpr decltype(auto) + operator*(const matrix &lhs, scalar_t a) noexcept; /// Matrix-vector multiplication template &lhs, /// Scalar multiplication template - requires(std::is_scalar_v || - std::is_same_v) -ALGEBRA_HOST_DEVICE constexpr matrix_t matrix_scalar_mul( - scalar_t a, const matrix_t &rhs, std::index_sequence) noexcept { +requires(std::is_scalar_v || + std::is_same_v) + ALGEBRA_HOST_DEVICE constexpr matrix_t + matrix_scalar_mul(scalar_t a, const matrix_t &rhs, + std::index_sequence) noexcept { return matrix_t{(a * rhs[J])...}; } @@ -250,9 +252,11 @@ ALGEBRA_HOST_DEVICE constexpr decltype(auto) operator-( template class array_t> - requires(std::is_scalar_v || std::is_same_v) -ALGEBRA_HOST_DEVICE constexpr decltype(auto) operator*( - scalar_t a, const matrix &rhs) noexcept { +requires(std::is_scalar_v || + std::is_same_v) ALGEBRA_HOST_DEVICE + constexpr decltype(auto) + operator*(scalar_t a, + const matrix &rhs) noexcept { using matrix_t = matrix; @@ -262,9 +266,9 @@ ALGEBRA_HOST_DEVICE constexpr decltype(auto) operator*( template class array_t> - requires(std::is_scalar_v || std::is_same_v) -constexpr decltype(auto) operator*( - const matrix &lhs, scalar_t a) noexcept { +requires(std::is_scalar_v || + std::is_same_v) constexpr decltype(auto) +operator*(const matrix &lhs, scalar_t a) noexcept { return a * lhs; } diff --git a/storage/common/include/algebra/storage/matrix_getter.hpp b/storage/common/include/algebra/storage/matrix_getter.hpp index cd3a0717..bd6db011 100644 --- a/storage/common/include/algebra/storage/matrix_getter.hpp +++ b/storage/common/include/algebra/storage/matrix_getter.hpp @@ -144,7 +144,7 @@ struct block_getter { template class array_t> - ALGEBRA_HOST_DEVICE inline constexpr auto operator()( + ALGEBRA_HOST_DEVICE constexpr auto operator()( const matrix &m, const std::size_t row, const std::size_t col) noexcept { @@ -181,7 +181,7 @@ struct block_getter { /// Get a vector of a const matrix template class array_t> - ALGEBRA_HOST_DEVICE inline constexpr auto operator()( + ALGEBRA_HOST_DEVICE constexpr auto operator()( const matrix &m, const std::size_t row, const std::size_t col) noexcept { @@ -214,7 +214,7 @@ struct block_getter { template class array_t> -ALGEBRA_HOST_DEVICE inline constexpr auto block( +ALGEBRA_HOST_DEVICE constexpr auto block( const matrix &m, const std::size_t row, const std::size_t col) noexcept { return block_getter{}.template operator()(m, row, col); @@ -224,7 +224,7 @@ ALGEBRA_HOST_DEVICE inline constexpr auto block( template class array_t> -ALGEBRA_HOST_DEVICE inline constexpr void set_block( +ALGEBRA_HOST_DEVICE constexpr void set_block( matrix &m, const matrix &b, const std::size_t row, const std::size_t col) noexcept { @@ -255,7 +255,7 @@ ALGEBRA_HOST_DEVICE inline constexpr void set_block( /// Operator setting a block with a vector template class array_t> -ALGEBRA_HOST_DEVICE inline constexpr void set_block( +ALGEBRA_HOST_DEVICE constexpr void set_block( matrix_t &m, const storage::vector &b, std::size_t row, std::size_t col) noexcept { assert(row < ROW); diff --git a/storage/eigen/include/algebra/storage/eigen.hpp b/storage/eigen/include/algebra/storage/eigen.hpp index cb193743..f6b8905c 100644 --- a/storage/eigen/include/algebra/storage/eigen.hpp +++ b/storage/eigen/include/algebra/storage/eigen.hpp @@ -32,43 +32,38 @@ using vector_type = storage_type; template using matrix_type = Eigen::Matrix; -/// 3-element "vector" type, using @c algebra::eigen::array +/// 3-element "vector" type, using @c eigen::vector_type template using vector3 = storage_type; -/// Point in 3D space, using @c algebra::eigen::array +/// Point in 3D space, using @c eigen::vector_type template using point3 = vector3; -/// 2-element "vector" type, using @c algebra::eigen::array +/// 2-element "vector" type, using @c eigen::vector_type template using vector2 = storage_type; -/// Point in 2D space, using @c algebra::eigen::array +/// Point in 2D space, using @c eigen::vector_type template using point2 = vector2; +/// Element Getter +using element_getter = eigen::storage::element_getter; +/// Block Getter +using block_getter = eigen::storage::block_getter; + } // namespace eigen -namespace trait { +ALGEBRA_PLUGINS_DEFINE_TYPE_TRAITS(eigen) -/// Type trait specializations -/// @{ +// Extra specializations needed for some additional eigen types +namespace trait { /// Index /// @{ -template -struct index> { - using type = algebra::eigen::size_type; -}; - template struct index> { using type = algebra::eigen::size_type; }; -template -struct index> { - using type = algebra::eigen::size_type; -}; - template struct index, bROWS, bCOLS, false>> { @@ -78,16 +73,6 @@ struct index, bROWS, /// Dimensions /// @{ -template -struct dimensions> { - - using size_type = index_t>; - - static constexpr size_type dim{1}; - static constexpr size_type rows{N}; - static constexpr size_type columns{1}; -}; - template struct dimensions> { @@ -100,16 +85,6 @@ struct dimensions> { Eigen::MatrixBase::ColsAtCompileTime}; }; -template -struct dimensions> { - - using size_type = index_t>; - - static constexpr size_type dim{2}; - static constexpr size_type rows{ROWS}; - static constexpr size_type columns{COLS}; -}; - template struct dimensions, bROWS, bCOLS, false>> { @@ -126,21 +101,11 @@ struct dimensions, /// Value /// @{ -template -struct value> { - using type = T; -}; - template struct value> { using type = typename Eigen::MatrixBase::value_type; }; -template -struct value> { - using type = T; -}; - template struct value, bROWS, bCOLS, false>> { @@ -150,33 +115,15 @@ struct value, bROWS, /// Vector /// @{ -template -struct vector> { - - template - using other_type = algebra::eigen::array; - - using type = other_type; -}; - template struct vector> { template - using other_type = algebra::eigen::array; + using other_type = eigen::vector_type; using type = other_type>, rows>>; }; - -template -struct vector> { - - template - using other_type = algebra::eigen::array; - - using type = other_type; -}; /// @} /// Matrix @@ -192,22 +139,6 @@ struct matrix> { using type = Eigen::MatrixBase; }; -template -struct matrix> { - template - using other_type = eigen::matrix_type; - - using type = Eigen::Matrix; -}; - -template -struct matrix> { - template - using other_type = eigen::matrix_type; - - using type = other_type; -}; - template struct matrix, bROWS, bCOLS, false>> { @@ -221,21 +152,11 @@ struct matrix, bROWS, /// Element getter /// @{ -template -struct element_getter> { - using type = eigen::storage::element_getter; -}; - template struct element_getter> { using type = eigen::storage::element_getter; }; -template -struct element_getter> { - using type = eigen::storage::element_getter; -}; - template struct element_getter, bROWS, bCOLS, false>> { @@ -249,12 +170,6 @@ template struct block_getter> { using type = eigen::storage::block_getter; }; - -template -struct block_getter> { - using type = eigen::storage::block_getter; -}; -/// @} /// @} } // namespace trait diff --git a/storage/eigen/include/algebra/storage/impl/eigen_getter.hpp b/storage/eigen/include/algebra/storage/impl/eigen_getter.hpp index 970a6f85..41073078 100644 --- a/storage/eigen/include/algebra/storage/impl/eigen_getter.hpp +++ b/storage/eigen/include/algebra/storage/impl/eigen_getter.hpp @@ -35,83 +35,73 @@ namespace algebra::eigen::storage { /// Functor used to access elements of Eigen matrices struct element_getter { /// Get non-const access to a matrix element - template , - Eigen::MatrixBase >::value && - std::is_convertible::value && - std::is_convertible::value, - bool> = true> - ALGEBRA_HOST_DEVICE inline auto &operator()( - Eigen::MatrixBase &m, size_type_1 row, - size_type_2 col) const { + template + requires(std::is_base_of_v< + Eigen::DenseCoeffsBase, + Eigen::MatrixBase > + &&std::is_convertible_v + &&std::is_convertible_v) + ALGEBRA_HOST_DEVICE inline auto & + operator()(Eigen::MatrixBase &m, size_type_1 row, + size_type_2 col) const { return m(static_cast(row), static_cast(col)); } /// Get const access to a matrix element - template ::value && - std::is_convertible::value, - bool> = true> - ALGEBRA_HOST_DEVICE inline auto operator()( - const Eigen::MatrixBase &m, size_type_1 row, - size_type_2 col) const { + template + requires(std::is_convertible_v + &&std::is_convertible_v) + ALGEBRA_HOST_DEVICE inline auto + operator()(const Eigen::MatrixBase &m, size_type_1 row, + size_type_2 col) const { return m(static_cast(row), static_cast(col)); } /// Get non-const access to a matrix element - template , - Eigen::MatrixBase >::value && - std::is_convertible::value, - bool> = true> - ALGEBRA_HOST_DEVICE inline auto &operator()( - Eigen::MatrixBase &m, size_type row) const { + template + requires(std::is_base_of_v< + Eigen::DenseCoeffsBase, + Eigen::MatrixBase > + &&std::is_convertible_v) + ALGEBRA_HOST_DEVICE inline auto & + operator()(Eigen::MatrixBase &m, size_type row) const { return m(static_cast(row)); } /// Get const access to a matrix element - template ::value, - bool> = true> - ALGEBRA_HOST_DEVICE inline auto operator()( - const Eigen::MatrixBase &m, size_type row) const { + template + requires std::is_convertible_v + ALGEBRA_HOST_DEVICE inline auto operator()( + const Eigen::MatrixBase &m, size_type row) const { return m(static_cast(row)); } }; // struct element_getter /// Function extracting an element from a matrix (const) -template < - typename derived_type> +template ALGEBRA_HOST_DEVICE inline auto element( const Eigen::MatrixBase &m, std::size_t row, std::size_t col) { - return element_getter()(m, static_cast(row), static_cast(col)); + return element_getter()(m, static_cast(row), + static_cast(col)); } /// Function extracting an element from a matrix (non-const) -template , - Eigen::MatrixBase >::value, - bool> = true> -ALGEBRA_HOST_DEVICE inline auto &element(Eigen::MatrixBase &m, - std::size_t row, std::size_t col) { - - return element_getter()(m, static_cast(row), static_cast(col)); +template +requires std::is_base_of_v< + Eigen::DenseCoeffsBase, + Eigen::MatrixBase > + ALGEBRA_HOST_DEVICE inline auto &element(Eigen::MatrixBase &m, + std::size_t row, std::size_t col) { + + return element_getter()(m, static_cast(row), + static_cast(col)); } /// Function extracting an element from a matrix (const) -template < - typename derived_type> +template ALGEBRA_HOST_DEVICE inline auto element( const Eigen::MatrixBase &m, std::size_t row) { @@ -119,14 +109,12 @@ ALGEBRA_HOST_DEVICE inline auto element( } /// Function extracting an element from a matrix (non-const) -template , - Eigen::MatrixBase >::value, - bool> = true> -ALGEBRA_HOST_DEVICE inline auto &element(Eigen::MatrixBase &m, - std::size_t row) { +template +requires std::is_base_of_v< + Eigen::DenseCoeffsBase, + Eigen::MatrixBase > + ALGEBRA_HOST_DEVICE inline auto &element(Eigen::MatrixBase &m, + std::size_t row) { return element_getter()(m, static_cast(row)); } @@ -134,70 +122,65 @@ ALGEBRA_HOST_DEVICE inline auto &element(Eigen::MatrixBase &m, /// Functor used to extract a block from Eigen matrices struct block_getter { template ::value && - std::is_convertible::value, - bool> = true> - ALGEBRA_HOST_DEVICE decltype(auto) operator()(const matrix_type &m, size_type_1 row, - size_type_2 col) const { + typename size_type_2> + requires(std::is_convertible_v + &&std::is_convertible_v) + ALGEBRA_HOST_DEVICE decltype(auto) + operator()(const matrix_type &m, size_type_1 row, size_type_2 col) const { return m.template block(row, col); } template ::value && - std::is_convertible::value, - bool> = true> - ALGEBRA_HOST_DEVICE decltype(auto) operator()(matrix_type &m, size_type_1 row, - size_type_2 col) const { + typename size_type_2> + requires(std::is_convertible_v + &&std::is_convertible_v) + ALGEBRA_HOST_DEVICE decltype(auto) + operator()(matrix_type &m, size_type_1 row, size_type_2 col) const { return m.template block(row, col); } template ::value && - std::is_convertible::value, - bool> = true> - ALGEBRA_HOST_DEVICE decltype(auto) operator()(matrix_type &m, size_type_1 row, - size_type_2 col) const { + typename size_type_2> + requires(std::is_convertible_v + &&std::is_convertible_v) + ALGEBRA_HOST_DEVICE decltype(auto) + operator()(matrix_type &m, size_type_1 row, size_type_2 col) const { return m.template block(row, col); } }; // struct block_getter /// Operator getting a block of a const matrix -template < - int ROWS, int COLS, class derived_type> -ALGEBRA_HOST_DEVICE decltype(auto) block(const Eigen::MatrixBase &m, - std::size_t row, std::size_t col) { - return block_getter{}.template operator()(m, static_cast(row), static_cast(col)); +template +ALGEBRA_HOST_DEVICE decltype(auto) block( + const Eigen::MatrixBase &m, std::size_t row, + std::size_t col) { + return block_getter{}.template operator()( + m, static_cast(row), static_cast(col)); } /// Operator getting a block of a const matrix -template < - int ROWS, int COLS, class derived_type> +template ALGEBRA_HOST_DEVICE decltype(auto) block(Eigen::MatrixBase &m, - std::size_t row, std::size_t col) { - return block_getter{}.template operator()(m, static_cast(row), static_cast(col)); + std::size_t row, std::size_t col) { + return block_getter{}.template operator()( + m, static_cast(row), static_cast(col)); } /// Function extracting a slice from the matrix template -ALGEBRA_HOST_DEVICE inline decltype(auto) vector(const Eigen::MatrixBase& m, - std::size_t row, std::size_t col) { +ALGEBRA_HOST_DEVICE inline decltype(auto) vector( + const Eigen::MatrixBase &m, std::size_t row, + std::size_t col) { - return block_getter{}.template operator()(m, static_cast(row), - static_cast(col)); + return block_getter{}.template operator()( + m, static_cast(row), static_cast(col)); } /// Operator setting a block -template < - typename derived_type1, typename derived_type2> +template ALGEBRA_HOST_DEVICE void set_block(Eigen::MatrixBase &m, const Eigen::MatrixBase &b, std::size_t row, std::size_t col) { diff --git a/storage/fastor/include/algebra/storage/fastor.hpp b/storage/fastor/include/algebra/storage/fastor.hpp index c58271f9..8b2ccb98 100644 --- a/storage/fastor/include/algebra/storage/fastor.hpp +++ b/storage/fastor/include/algebra/storage/fastor.hpp @@ -24,6 +24,9 @@ using size_type = std::size_t; /// Array type used in the Fastor storage model template using storage_type = Fastor::Tensor; +/// Vector type used in the Fastor storage model +template +using vector_type = storage_type; /// Matrix type used in the Fastor storage model template using matrix_type = algebra::fastor::Matrix; @@ -41,172 +44,13 @@ using vector2 = storage_type; template using point2 = vector2; -} // namespace fastor - -namespace trait { - -/// Type trait specializations -/// @{ - -/// Index -/// @{ -template -struct index> { - using type = std::size_t; -}; - -template -struct index> { - using type = std::size_t; -}; - -template -struct index> { - using type = std::size_t; -}; -/// @} - -/// Dimension -/// @{ -template -struct dimensions> { - - using size_type = std::size_t; - - static constexpr size_type dim{2}; - static constexpr size_type rows{ROWS}; - static constexpr size_type columns{COLS}; -}; - -template -struct dimensions> { - - using size_type = std::size_t; - - static constexpr size_type dim{2}; - static constexpr size_type rows{ROWS}; - static constexpr size_type columns{COLS}; -}; - -template -struct dimensions> { - - using size_type = std::size_t; - - static constexpr size_type dim{1}; - static constexpr size_type rows{N}; - static constexpr size_type columns{1}; -}; -/// @} - -/// Value -/// @{ -template -struct value> { - using type = T; -}; - -template -struct value> { - using type = T; -}; - -template -struct value> { - using type = T; -}; -/// @} - -/// Vector -/// @{ -template -struct vector> { +/// Element Getter +using element_getter = fastor::storage::element_getter; +/// Block Getter +using block_getter = fastor::storage::block_getter; - template - using other_type = Fastor::Tensor; - - using type = other_type; -}; - -template -struct vector> { - - template - using other_type = Fastor::Tensor; - - using type = Fastor::Tensor; -}; - -template -struct vector> { - - template - using other_type = Fastor::Tensor; - - using type = Fastor::Tensor; -}; -/// @} - -/// Matrix -/// @{ -template -struct matrix> { - template - using other_type = Fastor::Tensor; - - using type = Fastor::Tensor; -}; - -template -struct matrix> { - template - using other_type = algebra::fastor::Matrix; - - using type = algebra::fastor::Matrix; -}; - -template -struct matrix> { - template - using other_type = algebra::fastor::Matrix; - - using type = other_type; -}; -/// @} - -/// Element/Block Getter -/// @{ -template -struct element_getter> { - using type = fastor::storage::element_getter; -}; - -template -struct element_getter> { - using type = fastor::storage::element_getter; -}; - -template -struct element_getter> { - using type = fastor::storage::element_getter; -}; - -template -struct block_getter> { - using type = fastor::storage::block_getter; -}; - -template -struct block_getter> { - using type = fastor::storage::block_getter; -}; - -template -struct block_getter> { - using type = fastor::storage::block_getter; -}; -/// @} +} // namespace fastor -} // namespace trait +ALGEBRA_PLUGINS_DEFINE_TYPE_TRAITS(fastor) } // namespace algebra diff --git a/storage/smatrix/include/algebra/storage/impl/smatrix_getter.hpp b/storage/smatrix/include/algebra/storage/impl/smatrix_getter.hpp index 5184e0ba..1d32232e 100644 --- a/storage/smatrix/include/algebra/storage/impl/smatrix_getter.hpp +++ b/storage/smatrix/include/algebra/storage/impl/smatrix_getter.hpp @@ -23,19 +23,18 @@ namespace algebra::smatrix::storage { /// Functor used to access elements of SMatrix matrices -template struct element_getter { - template - ALGEBRA_HOST_DEVICE inline scalar_t &operator()(ROOT::Math::SMatrix &m, - unsigned int row, - unsigned int col) const { + template + ALGEBRA_HOST_DEVICE inline scalar_t &operator()( + ROOT::Math::SMatrix &m, unsigned int row, + unsigned int col) const { assert(row < ROWS); assert(col < COLS); return m(row, col); } - template + template ALGEBRA_HOST_DEVICE inline scalar_t operator()( const ROOT::Math::SMatrix &m, unsigned int row, unsigned int col) const { @@ -44,31 +43,31 @@ struct element_getter { return m(row, col); } - template - ALGEBRA_HOST_DEVICE inline scalar_t &operator()(ROOT::Math::SMatrix &m, - unsigned int row) const { - assert(row < ROWS); - return m(row); + template + ALGEBRA_HOST_DEVICE inline scalar_t &operator()( + ROOT::Math::SMatrix &m, unsigned int row) const { + assert(row < N); + return m(row, 0); } - template + template ALGEBRA_HOST_DEVICE inline scalar_t operator()( const ROOT::Math::SMatrix &m, unsigned int row) const { - assert(row < ROWS); - return m(row); + assert(row < N); + return m(row, 0); } - template - ALGEBRA_HOST_DEVICE inline scalar_t &operator()(ROOT::Math::SVector &m, - unsigned int row) const { - assert(row < ROWS); + template + ALGEBRA_HOST_DEVICE inline scalar_t &operator()( + ROOT::Math::SVector &m, unsigned int row) const { + assert(row < N); return m(row); } - template + template ALGEBRA_HOST_DEVICE inline scalar_t operator()( const ROOT::Math::SVector &m, unsigned int row) const { - assert(row < ROWS); + assert(row < N); return m(row); } }; // element_getter @@ -78,7 +77,8 @@ template ALGEBRA_HOST_DEVICE inline scalar_t element( const ROOT::Math::SMatrix &m, std::size_t row, std::size_t col) { - return element_getter()(m, static_cast(row), static_cast(col)); + return element_getter()(m, static_cast(row), + static_cast(col)); } /// Function extracting an element from a matrix (non-const) @@ -86,62 +86,68 @@ template ALGEBRA_HOST_DEVICE inline scalar_t &element( ROOT::Math::SMatrix &m, std::size_t row, std::size_t col) { - return element_getter()(m, static_cast(row), static_cast(col)); + return element_getter()(m, static_cast(row), + static_cast(col)); } /// Function extracting an element from a matrix (const) template ALGEBRA_HOST_DEVICE inline scalar_t element( const ROOT::Math::SMatrix &m, std::size_t row) { - return element_getter()(m, static_cast(row)); + return element_getter()(m, static_cast(row)); } /// Function extracting an element from a matrix (non-const) template ALGEBRA_HOST_DEVICE inline scalar_t &element( ROOT::Math::SMatrix &m, std::size_t row) { - return element_getter()(m, static_cast(row)); + return element_getter()(m, static_cast(row)); } /// Function extracting an element from a matrix (const) template ALGEBRA_HOST_DEVICE inline scalar_t element( const ROOT::Math::SVector &m, std::size_t row) { - return element_getter()(m, static_cast(row)); + return element_getter()(m, static_cast(row)); } /// Function extracting an element from a matrix (non-const) template ALGEBRA_HOST_DEVICE inline scalar_t &element( - ROOT::Math::SVector &m, std::size_t row) { - return element_getter()(m, static_cast(row)); + ROOT::Math::SVector &m, std::size_t row) { + return element_getter()(m, static_cast(row)); } /// Functor used to extract a block from SMatrix matrices struct block_getter { - template + template ALGEBRA_HOST_DEVICE ROOT::Math::SMatrix operator()( - const ROOT::Math::SMatrix &m, unsigned int row, unsigned int col) const { + const ROOT::Math::SMatrix &m, unsigned int row, + unsigned int col) const { return m.template Sub>(row, col); } - template + template ALGEBRA_HOST_DEVICE ROOT::Math::SVector operator()( - const ROOT::Math::SMatrix &m, unsigned int row, unsigned int col) const { + const ROOT::Math::SMatrix &m, unsigned int row, + unsigned int col) const { - return m.template SubCol>(col, row); + return m.template SubCol>(col, row); } }; // struct block_getter /// Operator getting a block of a const matrix -template -ALGEBRA_HOST_DEVICE matrix_type block(const ROOT::Math::SMatrix&m, - std::size_t row, - std::size_t col) { - return block_getter{}.template operator()(m, static_cast(row), static_cast(col)); +template +ALGEBRA_HOST_DEVICE ROOT::Math::SMatrix block( + const ROOT::Math::SMatrix &m, std::size_t row, + std::size_t col) { + return block_getter{}.template operator()( + m, static_cast(row), static_cast(col)); } /// Function extracting a slice from the matrix used by @@ -149,32 +155,35 @@ ALGEBRA_HOST_DEVICE matrix_type block(const ROOT::Math::SMatrix ALGEBRA_HOST_DEVICE inline auto vector( - const ROOT::Math::SMatrix& m, std::size_t row, + const ROOT::Math::SMatrix &m, std::size_t row, std::size_t col) { - return block_getter{}.template operator()(m, static_cast(row), static_cast(col)); + return block_getter{}.template operator()( + m, static_cast(row), static_cast(col)); } /// Operator setting a block with a matrix -template -ALGEBRA_HOST_DEVICE void set_block(input_matrix_type &m, - const matrix_type &b, - std::size_t row, std::size_t col) { +template +ALGEBRA_HOST_DEVICE void set_block( + input_matrix_type &m, const ROOT::Math::SMatrix &b, + std::size_t row, std::size_t col) { for (unsigned int i = 0; i < ROWS; ++i) { for (unsigned int j = 0; j < COLS; ++j) { - m(i + static_cast(row), j + static_cast(col)) = b(i, j); + m(i + static_cast(row), + j + static_cast(col)) = b(i, j); } } } /// Operator setting a block with a vector -template +template ALGEBRA_HOST_DEVICE void set_block(input_matrix_type &m, - const vector_type &b, unsigned int row, - unsigned int col) { + const ROOT::Math::SVector &b, + unsigned int row, unsigned int col) { for (unsigned int i = 0; i < ROWS; ++i) { m(i + row, col) = b[i]; } } -} // namespace algebra::smatrix +} // namespace algebra::smatrix::storage diff --git a/storage/smatrix/include/algebra/storage/smatrix.hpp b/storage/smatrix/include/algebra/storage/smatrix.hpp index 8527c10f..97169288 100644 --- a/storage/smatrix/include/algebra/storage/smatrix.hpp +++ b/storage/smatrix/include/algebra/storage/smatrix.hpp @@ -27,6 +27,9 @@ using size_type = unsigned int; /// Array type used in the SMatrix storage model template using storage_type = ROOT::Math::SVector; +/// Vector type used in the SMatrix storage model +template +using vector_type = storage_type; /// Matrix type used in the SMatrix storage model template using matrix_type = ROOT::Math::SMatrix; @@ -44,101 +47,13 @@ using vector2 = storage_type; template using point2 = vector2; -} // namespace smatrix - -namespace trait { - -/// Type trait specializations -/// @{ - -/// Index -/// @{ -template -struct index> { - using type = unsigned int; -}; -/// @} - -/// Dimension -/// @{ -template -struct dimensions> { - - using size_type = unsigned int; - - static constexpr size_type dim{2}; - static constexpr size_type rows{ROWS}; - static constexpr size_type columns{COLS}; -}; -/// @} - -/// Value -/// @{ -template -struct value> { - using type = T; -}; -/// @} - -/// Vector -/// @{ -template -struct vector> { - - template - using other_type = ROOT::Math::SVector; +/// Element Getter +using element_getter = smatrix::storage::element_getter; +/// Block Getter +using block_getter = smatrix::storage::block_getter; - using type = other_type; -}; - -template -struct vector> { - using type = ROOT::Math::SVector; - - template - using other_type = ROOT::Math::SVector; - - using type = other_type; -}; -/// @} - -/// Matrix -/// @{ -template -struct matrix> { - template - using other_type = ROOT::Math::SMatrix; - - using type = ROOT::Math::SMatrix; -}; - -template -struct matrix> { - template - using other_type = ROOT::Math::SMatrix; - - using type = other_type; -}; -/// @} - -/// Elemet/Block Getter -/// @{ -template -struct element_getter> { - using type = smatrix::storage::element_getter; -}; - -template -struct element_getter> { - using type = smatrix::storage::element_getter; -}; - -template -struct block_getter> { - using type = smatrix::storage::block_getter; -}; -/// @} +} // namespace smatrix -} // namespace trait +ALGEBRA_PLUGINS_DEFINE_TYPE_TRAITS(smatrix) } // namespace algebra diff --git a/storage/vc_aos/include/algebra/storage/impl/vc_aos_getter.hpp b/storage/vc_aos/include/algebra/storage/impl/vc_aos_getter.hpp index 459655a3..aa54f67a 100644 --- a/storage/vc_aos/include/algebra/storage/impl/vc_aos_getter.hpp +++ b/storage/vc_aos/include/algebra/storage/impl/vc_aos_getter.hpp @@ -20,7 +20,7 @@ using algebra::storage::set_block; /// Get a vector of a const matrix template class array_t> -ALGEBRA_HOST_DEVICE inline constexpr auto vector( +ALGEBRA_HOST_DEVICE constexpr auto vector( const algebra::storage::matrix &m, const std::size_t row, const std::size_t col) noexcept { return algebra::storage::block_getter{}.template operator()(m, row, diff --git a/storage/vc_aos/include/algebra/storage/vc_aos.hpp b/storage/vc_aos/include/algebra/storage/vc_aos.hpp index 4a5d334f..f3960d00 100644 --- a/storage/vc_aos/include/algebra/storage/vc_aos.hpp +++ b/storage/vc_aos/include/algebra/storage/vc_aos.hpp @@ -64,128 +64,13 @@ using vector6 = vector_type; template using vector8 = vector_type; -} // namespace vc_aos - -namespace trait { - -/// Type trait specializations -/// @{ - -/// Index -/// @{ -template -struct index> { - using type = algebra::vc_aos::size_type; -}; - -template -struct index> { - using type = algebra::vc_aos::size_type; -}; -/// @} - -/// Dimension -/// @{ -template -struct dimensions> { - - using size_type = - index_t>; - - static constexpr size_type dim{1}; - static constexpr size_type rows{N}; - static constexpr size_type columns{1}; -}; - -template -struct dimensions< - algebra::storage::matrix> { - - using size_type = - index_t>; - - static constexpr size_type dim{2}; - static constexpr size_type rows{ROWS}; - static constexpr size_type columns{COLS}; -}; -/// @} - -/// Value -/// @{ -template -struct value> { - using type = T; -}; +/// Element Getter +using element_getter = algebra::storage::element_getter; +/// Block Getter +using block_getter = algebra::storage::block_getter; -template -struct value> { - using type = T; -}; -/// @} - -/// Matrix -/// @{ -template -struct vector> { - - template - using other_type = - algebra::storage::vector; - - using type = other_type; -}; - -template -struct vector> { - - template - using other_type = - algebra::storage::vector; - - using type = other_type; -}; -/// @} - -/// Matrix -/// @{ -template -struct matrix> { - template - using other_type = algebra::storage::matrix; - - using type = algebra::storage::matrix; -}; - -template -struct matrix> { - template - using other_type = algebra::storage::matrix; - - using type = other_type; -}; -/// @} - -/// Elemet/Block Getter -/// @{ -template -struct element_getter> { - using type = algebra::storage::element_getter; -}; - -template -struct element_getter< - algebra::storage::matrix> { - using type = algebra::storage::element_getter; -}; +} // namespace vc_aos -template -struct block_getter< - algebra::storage::matrix> { - using type = algebra::storage::block_getter; -}; -/// @} -} // namespace trait +ALGEBRA_PLUGINS_DEFINE_TYPE_TRAITS(vc_aos) } // namespace algebra diff --git a/storage/vc_soa/include/algebra/storage/impl/vc_soa_getter.hpp b/storage/vc_soa/include/algebra/storage/impl/vc_soa_getter.hpp index 41a3e6fb..80418087 100644 --- a/storage/vc_soa/include/algebra/storage/impl/vc_soa_getter.hpp +++ b/storage/vc_soa/include/algebra/storage/impl/vc_soa_getter.hpp @@ -20,7 +20,7 @@ using algebra::storage::set_block; /// Get a vector of a const matrix template class array_t> -ALGEBRA_HOST_DEVICE inline constexpr auto vector( +ALGEBRA_HOST_DEVICE constexpr auto vector( const algebra::storage::matrix &m, const std::size_t row, const std::size_t col) noexcept { return algebra::storage::block_getter{}.template operator()(m, row, diff --git a/storage/vc_soa/include/algebra/storage/vc_soa.hpp b/storage/vc_soa/include/algebra/storage/vc_soa.hpp index 905062be..c1821d45 100644 --- a/storage/vc_soa/include/algebra/storage/vc_soa.hpp +++ b/storage/vc_soa/include/algebra/storage/vc_soa.hpp @@ -40,11 +40,11 @@ template using value_type = Vc::Vector; /// Vector type used in the Vc SoA storage model template -using vector_type = algebra::storage::vector, storage_type>; +using vector_type = algebra::storage::vector, std::array>; /// Matrix type used in the Vc SoA storage model template using matrix_type = - algebra::storage::matrix, ROWS, COLS>; + algebra::storage::matrix, ROWS, COLS>; /// 2-element "vector" type, using @c Vc::Vector in every element template @@ -65,113 +65,25 @@ using vector6 = vector_type; template using vector8 = vector_type; -} // namespace vc_soa - -namespace trait { +/// Element Getter +using element_getter = algebra::storage::element_getter; +/// Block Getter +using block_getter = algebra::storage::block_getter; -/// Type trait specializations -/// @{ - -/// Index -/// @{ -template -struct index, ROWS, COLS>> { - using type = algebra::vc_soa::size_type; -}; -/// @} - -/// Dimension -/// @{ -template -struct dimensions< - algebra::storage::matrix, ROWS, COLS>> { +} // namespace vc_soa - using size_type = - index_t, ROWS, COLS>>; +ALGEBRA_PLUGINS_DEFINE_TYPE_TRAITS(vc_soa) - static constexpr size_type dim{2}; - static constexpr size_type rows{ROWS}; - static constexpr size_type columns{COLS}; -}; -/// @} +namespace trait { -/// Value/Scalar +/// Make sure the simd scalar type is recognized correctly /// @{ -template -struct value, ROWS, COLS>> { - using type = T; -}; - template struct scalar, ROWS, COLS>> { using type = Vc::Vector; }; /// @} -/// Vector -/// @{ -template -struct vector, std::array>> { - - template - using other_type = - algebra::storage::vector, std::array>; - - using type = other_type; -}; - -template -struct vector, ROWS, COLS>> { - - template - using other_type = - algebra::storage::vector, std::array>; - - using type = other_type; -}; -/// @} - -/// Matrix -/// @{ -template -struct matrix, ROWS, COLS>> { - template - using other_type = algebra::storage::matrix, - other_ROWS, other_COLS>; - - using type = algebra::storage::matrix, ROWS, COLS>; -}; - -template -struct matrix, std::array>> { - template - using other_type = algebra::storage::matrix, - other_ROWS, other_COLS>; - - using type = other_type; -}; -/// @} - -/// Elemet/Block Getter -/// @{ -template -struct element_getter, std::array>> { - using type = algebra::storage::element_getter; -}; - -template -struct element_getter< - algebra::storage::matrix, ROWS, COLS>> { - using type = algebra::storage::element_getter; -}; - -template -struct block_getter< - algebra::storage::matrix, ROWS, COLS>> { - using type = algebra::storage::block_getter; -}; -/// @} - } // namespace trait } // namespace algebra diff --git a/storage/vecmem/include/algebra/storage/vecmem.hpp b/storage/vecmem/include/algebra/storage/vecmem.hpp index 77ef938e..ec76106a 100644 --- a/storage/vecmem/include/algebra/storage/vecmem.hpp +++ b/storage/vecmem/include/algebra/storage/vecmem.hpp @@ -21,9 +21,14 @@ namespace algebra { namespace vecmem { +/// size type for VecMem storage model +using size_type = std::size_t; /// Array type used in the VecMem storage model template using storage_type = ::vecmem::static_array; +/// Vector type used in the VecMem storage model +template +using vector_type = storage_type; /// Matrix type used in the VecMem storage model template using matrix_type = storage_type, COLS>; @@ -41,128 +46,13 @@ using vector2 = storage_type; template using point2 = vector2; -} // namespace vecmem - -namespace trait { - -/// Type trait specializations -/// @{ - -/// Index -/// @{ -template -struct index<::vecmem::static_array> { - using type = std::size_t; -}; - -template -struct index<::vecmem::static_array<::vecmem::static_array, COLS>> { - using type = std::size_t; -}; -/// @} - -/// Dimension -/// @{ -template -struct dimensions<::vecmem::static_array> { - - using size_type = index_t<::vecmem::static_array>; - - static constexpr size_type dim{1}; - static constexpr size_type rows{N}; - static constexpr size_type columns{1}; -}; - -template -struct dimensions< - ::vecmem::static_array<::vecmem::static_array, COLS>> { - - using size_type = - index_t<::vecmem::static_array<::vecmem::static_array, COLS>>; - - static constexpr size_type dim{2}; - static constexpr size_type rows{ROWS}; - static constexpr size_type columns{COLS}; -}; -/// @} - -/// Value -/// @{ -template -struct value<::vecmem::static_array> { - using type = T; -}; - -template -struct value<::vecmem::static_array<::vecmem::static_array, COLS>> { - using type = T; -}; -/// @} +/// Element Getter +using element_getter = cmath::storage::element_getter; +/// Block Getter +using block_getter = cmath::storage::block_getter; -/// Vector -/// @{ -template -struct vector<::vecmem::static_array> { - - template - using other_type = ::vecmem::static_array; - - using type = other_type; -}; - -template -struct vector<::vecmem::static_array<::vecmem::static_array, COLS>> { - - template - using other_type = ::vecmem::static_array; - - using type = other_type; -}; -/// @} - -/// Matrix -/// @{ -template -struct matrix<::vecmem::static_array<::vecmem::static_array, COLS>> { - template - using other_type = - ::vecmem::static_array<::vecmem::static_array, - other_COLS>; - - using type = ::vecmem::static_array<::vecmem::static_array, COLS>; -}; - -template -struct matrix<::vecmem::static_array> { - template - using other_type = - ::vecmem::static_array<::vecmem::static_array, - other_COLS>; - - using type = other_type; -}; -/// @} - -/// Elemet/Block Getter -/// @{ -template -struct element_getter<::vecmem::static_array> { - using type = cmath::storage::element_getter; -}; - -template -struct element_getter< - ::vecmem::static_array<::vecmem::static_array, COLS>> { - using type = cmath::storage::element_getter; -}; - -template -struct block_getter< - ::vecmem::static_array<::vecmem::static_array, COLS>> { - using type = cmath::storage::block_getter; -}; -/// @} +} // namespace vecmem -} // namespace trait +ALGEBRA_PLUGINS_DEFINE_TYPE_TRAITS(vecmem) } // namespace algebra diff --git a/tests/accelerator/sycl/CMakeLists.txt b/tests/accelerator/sycl/CMakeLists.txt index b8faa892..e8df7445 100644 --- a/tests/accelerator/sycl/CMakeLists.txt +++ b/tests/accelerator/sycl/CMakeLists.txt @@ -24,8 +24,8 @@ target_link_libraries( algebra_tests_sycl_common add_library( algebra::tests_sycl_common ALIAS algebra_tests_sycl_common ) # Set up all of the (available) SYCL tests. -algebra_add_test( array_sycl "array_generic.sycl" - LINK_LIBRARIES algebra::array_generic algebra::tests_sycl_common +algebra_add_test( array_sycl "array_cmath.sycl" + LINK_LIBRARIES algebra::array_cmath algebra::tests_sycl_common GTest::gtest_main ) if( ALGEBRA_PLUGINS_INCLUDE_EIGEN ) diff --git a/tests/accelerator/sycl/array_cmath.sycl b/tests/accelerator/sycl/array_cmath.sycl index bca3bcbe..c353adf2 100644 --- a/tests/accelerator/sycl/array_cmath.sycl +++ b/tests/accelerator/sycl/array_cmath.sycl @@ -6,7 +6,7 @@ */ // Project include(s). -#include "algebra/array_generic.hpp" +#include "algebra/array_cmath.hpp" // Local include(s). #include "test_sycl_basics.hpp" @@ -23,9 +23,9 @@ struct test_specialisation_name { static std::string GetName(int i) { switch (i) { case 0: - return "sycl_array_generic"; + return "sycl_array_cmath"; case 1: - return "sycl_array_generic"; + return "sycl_array_cmath"; default: return "unknown"; } @@ -44,6 +44,6 @@ typedef testing::Types< algebra::array::vector3, algebra::array::transform3, std::size_t, algebra::array::matrix_type>> - array_generic_types; + array_cmath_types; INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_sycl_basics, - array_generic_types, test_specialisation_name); + array_cmath_types, test_specialisation_name); diff --git a/tests/accelerator/sycl/eigen_cmath.sycl b/tests/accelerator/sycl/eigen_generic.sycl similarity index 100% rename from tests/accelerator/sycl/eigen_cmath.sycl rename to tests/accelerator/sycl/eigen_generic.sycl