From 06fc42aa0fe9c5e5951982075c5c9e221807110a Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay Date: Fri, 11 Feb 2022 16:40:32 +0100 Subject: [PATCH 1/5] Introduced the matrix_type definition for every storage type. --- storage/array/include/algebra/storage/array.hpp | 5 ++++- storage/eigen/include/algebra/storage/eigen.hpp | 5 ++++- storage/smatrix/include/algebra/storage/smatrix.hpp | 6 +++++- storage/vc/include/algebra/storage/vc.hpp | 3 +++ storage/vecmem/include/algebra/storage/vecmem.hpp | 5 ++++- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/storage/array/include/algebra/storage/array.hpp b/storage/array/include/algebra/storage/array.hpp index 50d66c86..e2a18180 100644 --- a/storage/array/include/algebra/storage/array.hpp +++ b/storage/array/include/algebra/storage/array.hpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -16,6 +16,9 @@ namespace algebra::array { /// Array type used in the Array storage model template using storage_type = std::array; +/// Matrix type used in the Array storage model +template +using matrix_type = storage_type, COLS>; /// 3-element "vector" type, using @c std::array template diff --git a/storage/eigen/include/algebra/storage/eigen.hpp b/storage/eigen/include/algebra/storage/eigen.hpp index b9922d8e..37e1d35f 100644 --- a/storage/eigen/include/algebra/storage/eigen.hpp +++ b/storage/eigen/include/algebra/storage/eigen.hpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -18,6 +18,9 @@ namespace algebra::eigen { /// Array type used in the Eigen storage model template using storage_type = array; +/// Matrix type used in the Eigen storage model +template +using matrix_type = Eigen::Matrix; /// 3-element "vector" type, using @c algebra::eigen::array template diff --git a/storage/smatrix/include/algebra/storage/smatrix.hpp b/storage/smatrix/include/algebra/storage/smatrix.hpp index 6e7b4e43..7089d0bd 100644 --- a/storage/smatrix/include/algebra/storage/smatrix.hpp +++ b/storage/smatrix/include/algebra/storage/smatrix.hpp @@ -8,6 +8,7 @@ #pragma once // ROOT/Smatrix include(s). +#include #include // System include(s). @@ -15,9 +16,12 @@ namespace algebra::smatrix { -/// Array type used in the Smatrix storage model +/// Array type used in the SMatrix storage model template using storage_type = ROOT::Math::SVector; +/// Matrix type used in the SMatrix storage model +template +using matrix_type = ROOT::Math::SMatrix; /// 3-element "vector" type, using @c ROOT::Math::SVector template diff --git a/storage/vc/include/algebra/storage/vc.hpp b/storage/vc/include/algebra/storage/vc.hpp index 26f3e25c..5601e0bf 100644 --- a/storage/vc/include/algebra/storage/vc.hpp +++ b/storage/vc/include/algebra/storage/vc.hpp @@ -28,6 +28,9 @@ namespace algebra::vc { /// Array type used in the Vc storage model template using storage_type = Vc::SimdArray; +/// Matrix type used in the Vc storage model +template +using matrix_type = Vc::array, COLS>; /// 3-element "vector" type, using @c algebra::vc::array4 template diff --git a/storage/vecmem/include/algebra/storage/vecmem.hpp b/storage/vecmem/include/algebra/storage/vecmem.hpp index 8fc287f2..4a571920 100644 --- a/storage/vecmem/include/algebra/storage/vecmem.hpp +++ b/storage/vecmem/include/algebra/storage/vecmem.hpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -18,6 +18,9 @@ namespace algebra::vecmem { /// Array type used in the VecMem storage model template using storage_type = ::vecmem::static_array; +/// Matrix type used in the VecMem storage model +template +using matrix_type = storage_type, COLS>; /// 3-element "vector" type, using @c vecmem::static_array template From 1e01eff7648bfefdac110d7fd42f5840011b2add Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay Date: Fri, 11 Feb 2022 16:45:23 +0100 Subject: [PATCH 2/5] Introduced algebra::getter::element for each frontend. In all cases made sure that the pre-existing element_getter functors would be put into a single location, and all users would use that single definition from now on. Moved the block_getter functors into central locations as well, although that was just for cleanup, it was not needed for the matrix handling (yet). --- .../include/algebra/array_cmath.hpp | 29 ++++++-- .../include/algebra/eigen_cmath.hpp | 54 +++++--------- .../include/algebra/eigen_eigen.hpp | 17 +++++ .../include/algebra/smatrix_cmath.hpp | 66 ++++++----------- .../include/algebra/smatrix_smatrix.hpp | 20 +++++- .../vc_cmath/include/algebra/vc_cmath.hpp | 71 ++++++------------- frontend/vc_vc/include/algebra/vc_vc.hpp | 18 +++++ .../include/algebra/vecmem_cmath.hpp | 22 +++++- .../algebra/math/impl/cmath_getter.hpp | 7 ++ .../algebra/math/impl/eigen_getter.hpp | 35 +++++++++ .../algebra/math/impl/eigen_transform3.hpp | 32 +-------- .../algebra/math/impl/smatrix_getter.hpp | 49 ++++++++++++- .../algebra/math/impl/smatrix_transform3.hpp | 23 +----- 13 files changed, 256 insertions(+), 187 deletions(-) diff --git a/frontend/array_cmath/include/algebra/array_cmath.hpp b/frontend/array_cmath/include/algebra/array_cmath.hpp index 75d2f4d4..88c220e5 100644 --- a/frontend/array_cmath/include/algebra/array_cmath.hpp +++ b/frontend/array_cmath/include/algebra/array_cmath.hpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -52,18 +52,37 @@ using cmath::theta; /// @} -/// Function extracting a slice from the matrix used by -/// @c algebra::array::transform3 +/// Function extracting a slice from a matrix template ALGEBRA_HOST_DEVICE inline array::storage_type vector( - const array::storage_type, COLS>& m, - std::size_t row, std::size_t col) { + const array::matrix_type& m, std::size_t row, + std::size_t col) { return cmath::vector_getter()(m, row, col); } +/// Function extracting an element from a matrix (const) +template +ALGEBRA_HOST_DEVICE inline scalar_t element( + const array::matrix_type& m, std::size_t row, + std::size_t col) { + + return cmath::element_getter()( + m, row, col); +} + +/// Function extracting an element from a matrix (non-const) +template +ALGEBRA_HOST_DEVICE inline scalar_t& element( + array::matrix_type& m, std::size_t row, + std::size_t col) { + + return cmath::element_getter()( + m, row, col); +} + } // namespace getter namespace vector { diff --git a/frontend/eigen_cmath/include/algebra/eigen_cmath.hpp b/frontend/eigen_cmath/include/algebra/eigen_cmath.hpp index 0493b102..1e2ef761 100644 --- a/frontend/eigen_cmath/include/algebra/eigen_cmath.hpp +++ b/frontend/eigen_cmath/include/algebra/eigen_cmath.hpp @@ -25,41 +25,6 @@ namespace algebra { namespace eigen { -/// Functor used to access elements of Eigen matrices -struct element_getter { - /// Get non-const access to a matrix element - template < - typename derived_type, - std::enable_if_t, - Eigen::MatrixBase >::value, - bool> = true> - ALGEBRA_HOST_DEVICE inline auto& operator()( - Eigen::MatrixBase& m, unsigned int row, - unsigned int col) const { - - return m(row, col); - } - /// Get const access to a matrix element - template - ALGEBRA_HOST_DEVICE inline auto operator()( - const Eigen::MatrixBase& m, unsigned int row, - unsigned int col) const { - - return m(row, col); - } -}; // struct element_getter - -/// Functor used to extract a block from Eigen matrices -struct block_getter { - template - ALGEBRA_HOST_DEVICE auto operator()(const matrix_type& m, std::size_t row, - std::size_t col) const { - - return m.template block(row, col); - } -}; // struct block_getter - /// @name cmath based transforms on @c algebra::eigen::storage_type /// @{ @@ -67,7 +32,7 @@ template using transform3 = cmath::transform3< std::size_t, eigen::storage_type, T, typename Eigen::Transform::MatrixType, - algebra::eigen::element_getter, algebra::eigen::block_getter>; + math::element_getter, math::block_getter>; template using cartesian2 = cmath::cartesian2 >; template @@ -101,6 +66,23 @@ ALGEBRA_HOST_DEVICE inline auto vector(const Eigen::MatrixBase& m, return m.template block(row, col); } +/// Function extracting an element from a matrix (const) +template +ALGEBRA_HOST_DEVICE inline auto element( + const Eigen::MatrixBase& m, std::size_t row, + std::size_t col) { + + return eigen::math::element_getter()(m, row, col); +} + +/// Function extracting an element from a matrix (non-const) +template +ALGEBRA_HOST_DEVICE inline auto& element(Eigen::MatrixBase& m, + std::size_t row, std::size_t col) { + + return eigen::math::element_getter()(m, row, col); +} + } // namespace getter namespace vector { diff --git a/frontend/eigen_eigen/include/algebra/eigen_eigen.hpp b/frontend/eigen_eigen/include/algebra/eigen_eigen.hpp index 1d1d5554..9449cd6d 100644 --- a/frontend/eigen_eigen/include/algebra/eigen_eigen.hpp +++ b/frontend/eigen_eigen/include/algebra/eigen_eigen.hpp @@ -60,6 +60,23 @@ ALGEBRA_HOST_DEVICE inline auto vector(const Eigen::MatrixBase& m, return m.template block(row, col); } +/// Function extracting an element from a matrix (const) +template +ALGEBRA_HOST_DEVICE inline auto element( + const Eigen::MatrixBase& m, std::size_t row, + std::size_t col) { + + return eigen::math::element_getter()(m, row, col); +} + +/// Function extracting an element from a matrix (non-const) +template +ALGEBRA_HOST_DEVICE inline auto& element(Eigen::MatrixBase& m, + std::size_t row, std::size_t col) { + + return eigen::math::element_getter()(m, row, col); +} + } // namespace getter namespace vector { diff --git a/frontend/smatrix_cmath/include/algebra/smatrix_cmath.hpp b/frontend/smatrix_cmath/include/algebra/smatrix_cmath.hpp index 7cc16909..84861f40 100644 --- a/frontend/smatrix_cmath/include/algebra/smatrix_cmath.hpp +++ b/frontend/smatrix_cmath/include/algebra/smatrix_cmath.hpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -18,52 +18,14 @@ namespace algebra { namespace smatrix { -/// Functor used to access elements of Vc matrices -template -struct element_getter { - - template - using matrix_type = ROOT::Math::SMatrix; - - template - ALGEBRA_HOST_DEVICE inline scalar_t& operator()(matrix_type& m, - unsigned int row, - unsigned int col) const { - - return m(col, row); - } - - template - ALGEBRA_HOST_DEVICE inline scalar_t operator()( - const matrix_type& m, unsigned int row, - unsigned int col) const { - - return m(col, row); - } -}; // element_getter - -/// Functor used to extract a block from Vc matrices -template -struct block_getter { - - template - using matrix_type = ROOT::Math::SMatrix; - - template - ALGEBRA_HOST_DEVICE matrix_type operator()( - const input_matrix_type& m, unsigned int row, unsigned int col) const { - - return m.template Sub >(row, col); - } -}; // struct block_getter - /// @name cmath based transforms on @c algebra::smatrix::storage_type /// @{ template -using transform3 = cmath::transform3, - element_getter, block_getter >; +using transform3 = + cmath::transform3, math::element_getter, + math::block_getter >; template using cartesian2 = cmath::cartesian2 >; template @@ -99,6 +61,24 @@ ALGEBRA_HOST_DEVICE inline auto vector( return m.template SubCol >(col, row); } +/// Function extracting an element from a matrix (const) +template +ALGEBRA_HOST_DEVICE inline scalar_t element( + const smatrix::matrix_type& m, std::size_t row, + std::size_t col) { + + return smatrix::math::element_getter()(m, row, col); +} + +/// Function extracting an element from a matrix (non-const) +template +ALGEBRA_HOST_DEVICE inline scalar_t& element( + smatrix::matrix_type& m, std::size_t row, + std::size_t col) { + + return smatrix::math::element_getter()(m, row, col); +} + } // namespace getter namespace vector { diff --git a/frontend/smatrix_smatrix/include/algebra/smatrix_smatrix.hpp b/frontend/smatrix_smatrix/include/algebra/smatrix_smatrix.hpp index 2e90be3a..640cb2ed 100644 --- a/frontend/smatrix_smatrix/include/algebra/smatrix_smatrix.hpp +++ b/frontend/smatrix_smatrix/include/algebra/smatrix_smatrix.hpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -54,6 +54,24 @@ ALGEBRA_HOST_DEVICE inline auto vector( return m.template SubCol >(col, row); } +/// Function extracting an element from a matrix (const) +template +ALGEBRA_HOST_DEVICE inline scalar_t element( + const smatrix::matrix_type& m, std::size_t row, + std::size_t col) { + + return smatrix::math::element_getter()(m, row, col); +} + +/// Function extracting an element from a matrix (non-const) +template +ALGEBRA_HOST_DEVICE inline scalar_t& element( + smatrix::matrix_type& m, std::size_t row, + std::size_t col) { + + return smatrix::math::element_getter()(m, row, col); +} + } // namespace getter namespace vector { diff --git a/frontend/vc_cmath/include/algebra/vc_cmath.hpp b/frontend/vc_cmath/include/algebra/vc_cmath.hpp index bd6f1c68..25ffbc87 100644 --- a/frontend/vc_cmath/include/algebra/vc_cmath.hpp +++ b/frontend/vc_cmath/include/algebra/vc_cmath.hpp @@ -24,51 +24,6 @@ using algebra::cmath::operator+; namespace algebra { namespace vc { -/// Functor used to access elements of Vc matrices -template -struct element_getter { - - template - using matrix_type = Vc::array, COLS>; - - template - ALGEBRA_HOST_DEVICE inline scalar_t& operator()(matrix_type& m, - std::size_t row, - std::size_t col) const { - - return m[col][row]; - } - - template - ALGEBRA_HOST_DEVICE inline scalar_t operator()( - const matrix_type& m, std::size_t row, - std::size_t col) const { - - return m[col][row]; - } -}; // element_getter - -/// Functor used to extract a block from Vc matrices -template -struct block_getter { - - template - using matrix_type = Vc::array, COLS>; - - template - ALGEBRA_HOST_DEVICE matrix_type operator()( - const input_matrix_type& m, std::size_t row, std::size_t col) const { - - matrix_type submatrix{}; - for (std::size_t icol = col; icol < col + COLS; ++icol) { - for (std::size_t irow = row; irow < row + ROWS; ++irow) { - submatrix[icol - col][irow - row] = m[icol][irow]; - } - } - return submatrix; - } -}; // struct block_getter - /// @name cmath based transforms on @c algebra::vc types /// @{ @@ -80,8 +35,10 @@ using math::phi; template using transform3 = cmath::transform3, 4>, element_getter, - block_getter, vc::vector3, vc::point2 >; + Vc::array, 4>, + cmath::element_getter, + cmath::block_getter, + vc::vector3, vc::point2 >; template using cartesian2 = cmath::cartesian2 >; template @@ -117,13 +74,31 @@ using vc::math::theta; template ALGEBRA_HOST_DEVICE inline vc::storage_type vector( - const Vc::array, COLS>& m, std::size_t row, + const vc::matrix_type& m, std::size_t row, std::size_t col) { return cmath::vector_getter >()(m, row, col); } +/// Function extracting an element from a matrix (const) +template +ALGEBRA_HOST_DEVICE inline scalar_t element( + const vc::matrix_type& m, std::size_t row, + std::size_t col) { + + return cmath::element_getter()(m, row, col); +} + +/// Function extracting an element from a matrix (non-const) +template +ALGEBRA_HOST_DEVICE inline scalar_t& element( + vc::matrix_type& m, std::size_t row, + std::size_t col) { + + return cmath::element_getter()(m, row, col); +} + } // namespace getter namespace vector { diff --git a/frontend/vc_vc/include/algebra/vc_vc.hpp b/frontend/vc_vc/include/algebra/vc_vc.hpp index bac282a5..e4a5618a 100644 --- a/frontend/vc_vc/include/algebra/vc_vc.hpp +++ b/frontend/vc_vc/include/algebra/vc_vc.hpp @@ -122,6 +122,24 @@ ALGEBRA_HOST_DEVICE inline auto vector( } } +/// Function extracting an element from a matrix (const) +template +ALGEBRA_HOST_DEVICE inline scalar_t element( + const vc::matrix_type& m, std::size_t row, + std::size_t col) { + + return cmath::element_getter()(m, row, col); +} + +/// Function extracting an element from a matrix (non-const) +template +ALGEBRA_HOST_DEVICE inline scalar_t& element( + vc::matrix_type& m, std::size_t row, + std::size_t col) { + + return cmath::element_getter()(m, row, col); +} + } // namespace getter namespace vector { diff --git a/frontend/vecmem_cmath/include/algebra/vecmem_cmath.hpp b/frontend/vecmem_cmath/include/algebra/vecmem_cmath.hpp index b00bdfe9..cb7228f4 100644 --- a/frontend/vecmem_cmath/include/algebra/vecmem_cmath.hpp +++ b/frontend/vecmem_cmath/include/algebra/vecmem_cmath.hpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -64,6 +64,26 @@ ALGEBRA_HOST_DEVICE inline vecmem::storage_type vector( SIZE>()(m, row, col); } +/// Function extracting an element from a matrix (const) +template +ALGEBRA_HOST_DEVICE inline scalar_t element( + const vecmem::matrix_type& m, std::size_t row, + std::size_t col) { + + return cmath::element_getter()( + m, row, col); +} + +/// Function extracting an element from a matrix (non-const) +template +ALGEBRA_HOST_DEVICE inline scalar_t& element( + vecmem::matrix_type& m, std::size_t row, + std::size_t col) { + + return cmath::element_getter()( + m, row, col); +} + } // namespace getter namespace vector { diff --git a/math/cmath/include/algebra/math/impl/cmath_getter.hpp b/math/cmath/include/algebra/math/impl/cmath_getter.hpp index cd9b0463..ae7f2151 100644 --- a/math/cmath/include/algebra/math/impl/cmath_getter.hpp +++ b/math/cmath/include/algebra/math/impl/cmath_getter.hpp @@ -12,6 +12,7 @@ #include "algebra/qualifiers.hpp" // System include(s). +#include #include #include @@ -104,6 +105,8 @@ struct element_getter { std::size_t row, std::size_t col) const { + assert(row < ROWS); + assert(col < COLS); return m[col][row]; } @@ -113,6 +116,8 @@ struct element_getter { const matrix_type &m, std::size_t row, std::size_t col) const { + assert(row < ROWS); + assert(col < COLS); return m[col][row]; } }; // struct element_getter @@ -134,6 +139,8 @@ struct vector_getter { ALGEBRA_HOST_DEVICE inline result_type operator()( const matrix_type &m, std::size_t row, std::size_t col) { + assert(col < COLS); + assert(row + SIZE < ROWS); result_type subvector{}; for (std::size_t irow = row; irow < row + SIZE; ++irow) { subvector[irow - row] = m[col][irow]; diff --git a/math/eigen/include/algebra/math/impl/eigen_getter.hpp b/math/eigen/include/algebra/math/impl/eigen_getter.hpp index a01cb1ec..c70df760 100644 --- a/math/eigen/include/algebra/math/impl/eigen_getter.hpp +++ b/math/eigen/include/algebra/math/impl/eigen_getter.hpp @@ -93,4 +93,39 @@ ALGEBRA_HOST_DEVICE inline auto eta( return algebra::math::atanh(v[2] / v.norm()); } +/// Functor used to access elements of Eigen matrices +struct element_getter { + /// Get non-const access to a matrix element + template < + typename derived_type, + std::enable_if_t, + Eigen::MatrixBase >::value, + bool> = true> + ALGEBRA_HOST_DEVICE inline auto &operator()( + Eigen::MatrixBase &m, unsigned int row, + unsigned int col) const { + + return m(row, col); + } + /// Get const access to a matrix element + template + ALGEBRA_HOST_DEVICE inline auto operator()( + const Eigen::MatrixBase &m, unsigned int row, + unsigned int col) const { + + return m(row, col); + } +}; // struct element_getter + +/// Functor used to extract a block from Eigen matrices +struct block_getter { + template + ALGEBRA_HOST_DEVICE auto operator()(const matrix_type &m, std::size_t row, + std::size_t col) const { + + return m.template block(row, col); + } +}; // struct block_getter + } // namespace algebra::eigen::math diff --git a/math/eigen/include/algebra/math/impl/eigen_transform3.hpp b/math/eigen/include/algebra/math/impl/eigen_transform3.hpp index 3b885d7f..0a25a719 100644 --- a/math/eigen/include/algebra/math/impl/eigen_transform3.hpp +++ b/math/eigen/include/algebra/math/impl/eigen_transform3.hpp @@ -25,36 +25,6 @@ namespace algebra::eigen::math { -namespace internal { - -/// Functor used to access elements of Eigen matrices -template -struct element_getter { - /// Get non-const access to a matrix element - template < - typename derived_type, - std::enable_if_t, - Eigen::MatrixBase >::value, - bool> = true> - ALGEBRA_HOST_DEVICE inline scalar_t &operator()( - Eigen::MatrixBase &m, unsigned int row, - unsigned int col) const { - - return m(row, col); - } - /// Get const access to a matrix element - template - ALGEBRA_HOST_DEVICE inline scalar_t operator()( - const Eigen::MatrixBase &m, unsigned int row, - unsigned int col) const { - - return m(row, col); - } -}; // struct element_getter - -} // namespace internal - /** Transform wrapper class to ensure standard API within differnt plugins */ template struct transform3 { @@ -80,7 +50,7 @@ struct transform3 { typename Eigen::Transform::MatrixType; /// Function (object) used for accessing a matrix element - using element_getter = internal::element_getter; + using element_getter = algebra::eigen::math::element_getter; /// @} diff --git a/math/smatrix/include/algebra/math/impl/smatrix_getter.hpp b/math/smatrix/include/algebra/math/impl/smatrix_getter.hpp index 53997b73..53df61b4 100644 --- a/math/smatrix/include/algebra/math/impl/smatrix_getter.hpp +++ b/math/smatrix/include/algebra/math/impl/smatrix_getter.hpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -13,9 +13,13 @@ // ROOT/Smatrix include(s). #include #include +#include #include #include +// System include(s). +#include + namespace algebra::smatrix::math { /** This method retrieves phi from a vector, vector base with rows >= 2 @@ -114,4 +118,47 @@ ALGEBRA_HOST inline scalar_t perp( return TMath::Sqrt(v.apply(0) * v.apply(0) + v.apply(1) * v.apply(1)); } +/// Functor used to access elements of Vc matrices +template +struct element_getter { + + template + using matrix_type = ROOT::Math::SMatrix; + + template + ALGEBRA_HOST_DEVICE inline scalar_t &operator()(matrix_type &m, + unsigned int row, + unsigned int col) const { + + assert(row < ROWS); + assert(col < COLS); + return m(row, col); + } + + template + ALGEBRA_HOST_DEVICE inline scalar_t operator()( + const matrix_type &m, unsigned int row, + unsigned int col) const { + + assert(row < ROWS); + assert(col < COLS); + return m(row, col); + } +}; // element_getter + +/// Functor used to extract a block from SMatrix matrices +template +struct block_getter { + + template + using matrix_type = ROOT::Math::SMatrix; + + template + ALGEBRA_HOST_DEVICE matrix_type operator()( + const input_matrix_type &m, unsigned int row, unsigned int col) const { + + return m.template Sub >(row, col); + } +}; // struct block_getter + } // namespace algebra::smatrix::math diff --git a/math/smatrix/include/algebra/math/impl/smatrix_transform3.hpp b/math/smatrix/include/algebra/math/impl/smatrix_transform3.hpp index 32ef072a..f16df305 100644 --- a/math/smatrix/include/algebra/math/impl/smatrix_transform3.hpp +++ b/math/smatrix/include/algebra/math/impl/smatrix_transform3.hpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -17,25 +17,6 @@ namespace algebra::smatrix::math { -namespace internal { - -/// Functor used to access elements of SMatrix matrices -template -struct element_getter { - /// The matrix type used by this struct - template - using matrix_type = ROOT::Math::SMatrix; - /// Get const access to a matrix element - template - ALGEBRA_HOST inline scalar_t operator()(const matrix_type &m, - unsigned int row, - unsigned int col) const { - return m(row, col); - } -}; // element_getter - -} // namespace internal - /** Transform wrapper class to ensure standard API within differnt plugins * **/ @@ -62,7 +43,7 @@ struct transform3 { using matrix44 = ROOT::Math::SMatrix; /// Function (object) used for accessing a matrix element - using element_getter = internal::element_getter; + using element_getter = algebra::smatrix::math::element_getter; /// @} From 292421b1856eab3051c00730660f40a9e3d4a233 Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay Date: Fri, 11 Feb 2022 16:50:39 +0100 Subject: [PATCH 3/5] Introduced trivial tests using asymmetric 6x4 matrices. Testing the behaviour of all matrix types in both host and device code. --- tests/accelerator/common/test_basics_base.hpp | 12 +++++++ .../common/test_basics_functors.hpp | 20 ++++++++++++ tests/accelerator/cuda/array_cmath.cu | 8 +++-- .../cuda/common/test_cuda_basics.cuh | 18 ++++++++++- tests/accelerator/cuda/eigen_cmath.cu | 8 +++-- tests/accelerator/cuda/eigen_eigen.cu | 8 +++-- tests/accelerator/cuda/vecmem_cmath.cu | 8 +++-- tests/accelerator/sycl/array_cmath.sycl | 6 ++-- .../sycl/common/test_sycl_basics.hpp | 18 ++++++++++- tests/accelerator/sycl/vecmem_cmath.sycl | 6 ++-- tests/array/array_cmath.cpp | 8 +++-- tests/common/test_base.hpp | 9 ++++-- tests/common/test_device_basics.hpp | 24 ++++++++++++++ tests/common/test_host_basics.hpp | 32 +++++++++++++++++-- tests/common/test_types.hpp | 9 ++++-- tests/eigen/eigen_cmath.cpp | 8 +++-- tests/eigen/eigen_eigen.cpp | 8 +++-- tests/smatrix/smatrix_cmath.cpp | 8 +++-- tests/smatrix/smatrix_smatrix.cpp | 8 +++-- tests/vc/vc_cmath.cpp | 9 +++--- tests/vc/vc_vc.cpp | 9 +++--- tests/vecmem/vecmem_cmath.cpp | 8 +++-- 22 files changed, 202 insertions(+), 50 deletions(-) diff --git a/tests/accelerator/common/test_basics_base.hpp b/tests/accelerator/common/test_basics_base.hpp index 53641f2a..8306d415 100644 --- a/tests/accelerator/common/test_basics_base.hpp +++ b/tests/accelerator/common/test_basics_base.hpp @@ -51,6 +51,10 @@ class test_basics_base : public testing::Test, public test_base { m_v2 = std::make_unique >(s_arraySize, &m_resource); + m_m1 = + std::make_unique > >( + s_arraySize, &m_resource); + m_output_host = std::make_unique >( s_arraySize, &m_resource); m_output_device = std::make_unique >( @@ -81,6 +85,13 @@ class test_basics_base : public testing::Test, public test_base { static_cast(i * 2.3), static_cast((i + 2) * 3.4)}; + for (typename T::size_type j = 0; j < 6; ++j) { + for (typename T::size_type k = 0; k < 4; ++k) { + algebra::getter::element(m_m1->at(i), j, k) = + static_cast(j * 20.3 + k * 10.5); + } + } + m_output_host->at(i) = 0; m_output_device->at(i) = 0; } @@ -122,6 +133,7 @@ class test_basics_base : public testing::Test, public test_base { std::unique_ptr > m_t1, m_t2, m_t3; std::unique_ptr > m_p1, m_p2; std::unique_ptr > m_v1, m_v2; + std::unique_ptr > > m_m1; /// @} diff --git a/tests/accelerator/common/test_basics_functors.hpp b/tests/accelerator/common/test_basics_functors.hpp index 62462715..96d3518a 100644 --- a/tests/accelerator/common/test_basics_functors.hpp +++ b/tests/accelerator/common/test_basics_functors.hpp @@ -66,6 +66,26 @@ class vector_3d_ops_functor : public functor_base { } }; +/// Functor running @c test_device_basics::matrix64_ops +template +class matrix64_ops_functor : public functor_base { + + public: + ALGEBRA_HOST_DEVICE void operator()( + std::size_t i, + vecmem::data::vector_view > m, + vecmem::data::vector_view output) const { + + // Create the VecMem vector(s). + vecmem::device_vector > vec_m(m); + vecmem::device_vector vec_output(output); + + // Perform the operation. + auto ii = static_cast(i); + vec_output[ii] = this->m_tester.matrix64_ops(vec_m[ii]); + } +}; + /// Functor running @c test_device_basics::transform3_ops template class transform3_ops_functor : public functor_base { diff --git a/tests/accelerator/cuda/array_cmath.cu b/tests/accelerator/cuda/array_cmath.cu index 9de77a7a..c06141da 100644 --- a/tests/accelerator/cuda/array_cmath.cu +++ b/tests/accelerator/cuda/array_cmath.cu @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -38,12 +38,14 @@ typedef testing::Types< float, algebra::array::point2, algebra::array::point3, algebra::array::vector2, algebra::array::vector3, algebra::array::transform3, algebra::array::cartesian2, - algebra::array::polar2, algebra::array::cylindrical2 >, + algebra::array::polar2, algebra::array::cylindrical2, + std::size_t, algebra::array::matrix_type>, test_types< double, algebra::array::point2, algebra::array::point3, algebra::array::vector2, algebra::array::vector3, algebra::array::transform3, algebra::array::cartesian2, - algebra::array::polar2, algebra::array::cylindrical2 > > + algebra::array::polar2, algebra::array::cylindrical2, + std::size_t, algebra::array::matrix_type> > array_cmath_types; INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_cuda_basics, array_cmath_types, test_specialisation_name); diff --git a/tests/accelerator/cuda/common/test_cuda_basics.cuh b/tests/accelerator/cuda/common/test_cuda_basics.cuh index d969b17b..556e54c6 100644 --- a/tests/accelerator/cuda/common/test_cuda_basics.cuh +++ b/tests/accelerator/cuda/common/test_cuda_basics.cuh @@ -76,6 +76,21 @@ TYPED_TEST_P(test_cuda_basics, vector_3d_ops) { this->compareOutputs(); } +/// Test for handling matrices +TYPED_TEST_P(test_cuda_basics, matrix64_ops) { + + // Run the test on the host, and on the/a device. + execute_host_test >( + this->m_m1->size(), vecmem::get_data(*(this->m_m1)), + vecmem::get_data(*(this->m_output_host))); + execute_cuda_test >( + this->m_m1->size(), vecmem::get_data(*(this->m_m1)), + vecmem::get_data(*(this->m_output_device))); + + // Compare the outputs. + this->compareOutputs(); +} + /// Test for some operations with @c transform3 TYPED_TEST_P(test_cuda_basics, transform3) { @@ -153,4 +168,5 @@ TYPED_TEST_P(test_cuda_basics, polar2) { } REGISTER_TYPED_TEST_SUITE_P(test_cuda_basics, vector_2d_ops, vector_3d_ops, - transform3, cartesian2, cylindrical2, polar2); + matrix64_ops, transform3, cartesian2, cylindrical2, + polar2); diff --git a/tests/accelerator/cuda/eigen_cmath.cu b/tests/accelerator/cuda/eigen_cmath.cu index 48ae6a7f..83d1e19b 100644 --- a/tests/accelerator/cuda/eigen_cmath.cu +++ b/tests/accelerator/cuda/eigen_cmath.cu @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -38,12 +38,14 @@ typedef testing::Types< float, algebra::eigen::point2, algebra::eigen::point3, algebra::eigen::vector2, algebra::eigen::vector3, algebra::eigen::transform3, algebra::eigen::cartesian2, - algebra::eigen::polar2, algebra::eigen::cylindrical2 >, + algebra::eigen::polar2, algebra::eigen::cylindrical2, + std::size_t, algebra::eigen::matrix_type>, test_types< double, algebra::eigen::point2, algebra::eigen::point3, algebra::eigen::vector2, algebra::eigen::vector3, algebra::eigen::transform3, algebra::eigen::cartesian2, - algebra::eigen::polar2, algebra::eigen::cylindrical2 > > + algebra::eigen::polar2, algebra::eigen::cylindrical2, + std::size_t, algebra::eigen::matrix_type> > eigen_cmath_types; INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_cuda_basics, eigen_cmath_types, test_specialisation_name); diff --git a/tests/accelerator/cuda/eigen_eigen.cu b/tests/accelerator/cuda/eigen_eigen.cu index 1ae9eaf6..93caacc7 100644 --- a/tests/accelerator/cuda/eigen_eigen.cu +++ b/tests/accelerator/cuda/eigen_eigen.cu @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -38,12 +38,14 @@ typedef testing::Types< float, algebra::eigen::point2, algebra::eigen::point3, algebra::eigen::vector2, algebra::eigen::vector3, algebra::eigen::transform3, algebra::eigen::cartesian2, - algebra::eigen::polar2, algebra::eigen::cylindrical2 >, + algebra::eigen::polar2, algebra::eigen::cylindrical2, + std::size_t, algebra::eigen::matrix_type>, test_types< double, algebra::eigen::point2, algebra::eigen::point3, algebra::eigen::vector2, algebra::eigen::vector3, algebra::eigen::transform3, algebra::eigen::cartesian2, - algebra::eigen::polar2, algebra::eigen::cylindrical2 > > + algebra::eigen::polar2, algebra::eigen::cylindrical2, + std::size_t, algebra::eigen::matrix_type> > eigen_eigen_types; INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_cuda_basics, eigen_eigen_types, test_specialisation_name); diff --git a/tests/accelerator/cuda/vecmem_cmath.cu b/tests/accelerator/cuda/vecmem_cmath.cu index 73f80bc2..7179f1cf 100644 --- a/tests/accelerator/cuda/vecmem_cmath.cu +++ b/tests/accelerator/cuda/vecmem_cmath.cu @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -38,13 +38,15 @@ typedef testing::Types< float, algebra::vecmem::point2, algebra::vecmem::point3, algebra::vecmem::vector2, algebra::vecmem::vector3, algebra::vecmem::transform3, algebra::vecmem::cartesian2, - algebra::vecmem::polar2, algebra::vecmem::cylindrical2 >, + algebra::vecmem::polar2, algebra::vecmem::cylindrical2, + std::size_t, algebra::vecmem::matrix_type>, test_types< double, algebra::vecmem::point2, algebra::vecmem::point3, algebra::vecmem::vector2, algebra::vecmem::vector3, algebra::vecmem::transform3, algebra::vecmem::cartesian2, algebra::vecmem::polar2, - algebra::vecmem::cylindrical2 > > + algebra::vecmem::cylindrical2, std::size_t, + algebra::vecmem::matrix_type> > vecmem_cmath_types; INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_cuda_basics, vecmem_cmath_types, test_specialisation_name); diff --git a/tests/accelerator/sycl/array_cmath.sycl b/tests/accelerator/sycl/array_cmath.sycl index 21ecaddd..112c2f40 100644 --- a/tests/accelerator/sycl/array_cmath.sycl +++ b/tests/accelerator/sycl/array_cmath.sycl @@ -38,12 +38,14 @@ typedef testing::Types< float, algebra::array::point2, algebra::array::point3, algebra::array::vector2, algebra::array::vector3, algebra::array::transform3, algebra::array::cartesian2, - algebra::array::polar2, algebra::array::cylindrical2 >, + algebra::array::polar2, algebra::array::cylindrical2, + std::size_t, algebra::array::matrix_type>, test_types< double, algebra::array::point2, algebra::array::point3, algebra::array::vector2, algebra::array::vector3, algebra::array::transform3, algebra::array::cartesian2, - algebra::array::polar2, algebra::array::cylindrical2 > > + algebra::array::polar2, algebra::array::cylindrical2, + std::size_t, algebra::array::matrix_type> > array_cmath_types; INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_sycl_basics, array_cmath_types, test_specialisation_name); diff --git a/tests/accelerator/sycl/common/test_sycl_basics.hpp b/tests/accelerator/sycl/common/test_sycl_basics.hpp index a7ffb718..9388f039 100644 --- a/tests/accelerator/sycl/common/test_sycl_basics.hpp +++ b/tests/accelerator/sycl/common/test_sycl_basics.hpp @@ -81,6 +81,21 @@ TYPED_TEST_P(test_sycl_basics, vector_3d_ops) { this->compareOutputs(); } +/// Test for handling matrices +TYPED_TEST_P(test_sycl_basics, matrix64_ops) { + + // Run the test on the host, and on the/a device. + execute_host_test >( + this->m_m1->size(), vecmem::get_data(*(this->m_m1)), + vecmem::get_data(*(this->m_output_host))); + execute_sycl_test >( + this->m_queue, this->m_m1->size(), vecmem::get_data(*(this->m_m1)), + vecmem::get_data(*(this->m_output_device))); + + // Compare the outputs. + this->compareOutputs(); +} + /// Test for some operations with @c transform3 TYPED_TEST_P(test_sycl_basics, transform3) { @@ -158,4 +173,5 @@ TYPED_TEST_P(test_sycl_basics, polar2) { } REGISTER_TYPED_TEST_SUITE_P(test_sycl_basics, vector_2d_ops, vector_3d_ops, - transform3, cartesian2, cylindrical2, polar2); + matrix64_ops, transform3, cartesian2, cylindrical2, + polar2); diff --git a/tests/accelerator/sycl/vecmem_cmath.sycl b/tests/accelerator/sycl/vecmem_cmath.sycl index 1a173c4b..a211aa71 100644 --- a/tests/accelerator/sycl/vecmem_cmath.sycl +++ b/tests/accelerator/sycl/vecmem_cmath.sycl @@ -38,13 +38,15 @@ typedef testing::Types< float, algebra::vecmem::point2, algebra::vecmem::point3, algebra::vecmem::vector2, algebra::vecmem::vector3, algebra::vecmem::transform3, algebra::vecmem::cartesian2, - algebra::vecmem::polar2, algebra::vecmem::cylindrical2 >, + algebra::vecmem::polar2, algebra::vecmem::cylindrical2, + std::size_t, algebra::vecmem::matrix_type>, test_types< double, algebra::vecmem::point2, algebra::vecmem::point3, algebra::vecmem::vector2, algebra::vecmem::vector3, algebra::vecmem::transform3, algebra::vecmem::cartesian2, algebra::vecmem::polar2, - algebra::vecmem::cylindrical2 > > + algebra::vecmem::cylindrical2, std::size_t, + algebra::vecmem::matrix_type> > vecmem_cmath_types; INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_sycl_basics, vecmem_cmath_types, test_specialisation_name); diff --git a/tests/array/array_cmath.cpp b/tests/array/array_cmath.cpp index b83e0870..4d43d256 100644 --- a/tests/array/array_cmath.cpp +++ b/tests/array/array_cmath.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -38,12 +38,14 @@ typedef testing::Types< float, algebra::array::point2, algebra::array::point3, algebra::array::vector2, algebra::array::vector3, algebra::array::transform3, algebra::array::cartesian2, - algebra::array::polar2, algebra::array::cylindrical2 >, + algebra::array::polar2, algebra::array::cylindrical2, + std::size_t, algebra::array::matrix_type>, test_types< double, algebra::array::point2, algebra::array::point3, algebra::array::vector2, algebra::array::vector3, algebra::array::transform3, algebra::array::cartesian2, - algebra::array::polar2, algebra::array::cylindrical2 > > + algebra::array::polar2, algebra::array::cylindrical2, + std::size_t, algebra::array::matrix_type> > array_cmath_types; INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_host_basics, array_cmath_types, test_specialisation_name); diff --git a/tests/common/test_base.hpp b/tests/common/test_base.hpp index e1357200..c88d2bea 100644 --- a/tests/common/test_base.hpp +++ b/tests/common/test_base.hpp @@ -20,10 +20,12 @@ class test_base {}; /// Test base class, using a @c test_types type argument template + typename cartesian2_t, typename polar2_t, typename cylindrical2_t, + typename size_ty, + template class matrix_t> class test_base< test_types > { + cartesian2_t, polar2_t, cylindrical2_t, size_ty, matrix_t> > { public: /// @name Type definitions @@ -38,6 +40,9 @@ class test_base< using cartesian2 = cartesian2_t; using polar2 = polar2_t; using cylindrical2 = cylindrical2_t; + using size_type = size_ty; + template + using matrix = matrix_t; /// @} diff --git a/tests/common/test_device_basics.hpp b/tests/common/test_device_basics.hpp index d8d05be1..1f238022 100644 --- a/tests/common/test_device_basics.hpp +++ b/tests/common/test_device_basics.hpp @@ -34,6 +34,9 @@ class test_device_basics : public test_base { using cartesian2 = typename test_base::cartesian2; using polar2 = typename test_base::polar2; using cylindrical2 = typename test_base::cylindrical2; + using size_type = typename test_base::size_type; + template + using matrix = typename test_base::template matrix; /// @} @@ -75,6 +78,27 @@ class test_device_basics : public test_base { return (phi + perp + norm1 + dot + norm3); } + /// Perform some trivial operations on an asymmetrix matrix + ALGEBRA_HOST_DEVICE + scalar matrix64_ops(const matrix<6, 4>& m) const { + + matrix<6, 4> m2; + for (size_type i = 0; i < 6; ++i) { + for (size_type j = 0; j < 4; ++j) { + algebra::getter::element(m2, i, j) = algebra::getter::element(m, i, j); + } + } + + scalar result = 0.; + for (size_type i = 0; i < 6; ++i) { + for (size_type j = 0; j < 4; ++j) { + result += 0.6 * algebra::getter::element(m, i, j) + + 0.7 * algebra::getter::element(m2, i, j); + } + } + return result; + } + /// Perform various operations using the @c transform3 type ALGEBRA_HOST_DEVICE scalar transform3_ops(vector3 t1, vector3 t2, vector3 t3, vector3 a, diff --git a/tests/common/test_host_basics.hpp b/tests/common/test_host_basics.hpp index da493cae..6c8b39b7 100644 --- a/tests/common/test_host_basics.hpp +++ b/tests/common/test_host_basics.hpp @@ -107,6 +107,34 @@ TYPED_TEST_P(test_host_basics, vector3) { ASSERT_NEAR(norm, std::sqrt(3.), this->m_epsilon); } +// Test generic access to a 6x4 matrix +TYPED_TEST_P(test_host_basics, matrix64) { + + // Create the matrix. + static constexpr typename TypeParam::size_type ROWS = 6; + static constexpr typename TypeParam::size_type COLS = 4; + typename TypeParam::template matrix m; + + // Fill it. + for (typename TypeParam::size_type i = 0; i < ROWS; ++i) { + for (typename TypeParam::size_type j = 0; j < COLS; ++j) { + algebra::getter::element(m, i, j) = + static_cast(0.5 * i + j); + } + } + + // Check its content. + const typename TypeParam::template matrix& m_const_ref = m; + for (typename TypeParam::size_type i = 0; i < ROWS; ++i) { + for (typename TypeParam::size_type j = 0; j < COLS; ++j) { + const typename TypeParam::scalar ref = + static_cast(0.5 * i + j); + EXPECT_FLOAT_EQ(algebra::getter::element(m, i, j), ref); + EXPECT_FLOAT_EQ(algebra::getter::element(m_const_ref, i, j), ref); + } + } +} + // This defines the vector operation test suite TYPED_TEST_P(test_host_basics, getter) { @@ -293,6 +321,6 @@ TYPED_TEST_P(test_host_basics, local_transformations) { ASSERT_NEAR(polfrom2[1], polfrom3[1], this->m_epsilon); } -REGISTER_TYPED_TEST_SUITE_P(test_host_basics, local_vectors, vector3, getter, - transform3, global_transformations, +REGISTER_TYPED_TEST_SUITE_P(test_host_basics, local_vectors, vector3, matrix64, + getter, transform3, global_transformations, local_transformations); diff --git a/tests/common/test_types.hpp b/tests/common/test_types.hpp index 66fe9f0b..2e51599f 100644 --- a/tests/common/test_types.hpp +++ b/tests/common/test_types.hpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -10,7 +10,9 @@ /// Simple struct holding the types that describe a given plugin template + typename cartesian2_t, typename polar2_t, typename cylindrical2_t, + typename size_ty, + template class matrix_t> struct test_types { using scalar = scalar_t; @@ -22,5 +24,8 @@ struct test_types { using cartesian2 = cartesian2_t; using polar2 = polar2_t; using cylindrical2 = cylindrical2_t; + using size_type = size_ty; + template + using matrix = matrix_t; }; // struct test_types diff --git a/tests/eigen/eigen_cmath.cpp b/tests/eigen/eigen_cmath.cpp index 67bc1534..bf8bd4aa 100644 --- a/tests/eigen/eigen_cmath.cpp +++ b/tests/eigen/eigen_cmath.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -38,12 +38,14 @@ typedef testing::Types< float, algebra::eigen::point2, algebra::eigen::point3, algebra::eigen::vector2, algebra::eigen::vector3, algebra::eigen::transform3, algebra::eigen::cartesian2, - algebra::eigen::polar2, algebra::eigen::cylindrical2 >, + algebra::eigen::polar2, algebra::eigen::cylindrical2, + std::size_t, algebra::eigen::matrix_type>, test_types< double, algebra::eigen::point2, algebra::eigen::point3, algebra::eigen::vector2, algebra::eigen::vector3, algebra::eigen::transform3, algebra::eigen::cartesian2, - algebra::eigen::polar2, algebra::eigen::cylindrical2 > > + algebra::eigen::polar2, algebra::eigen::cylindrical2, + std::size_t, algebra::eigen::matrix_type> > eigen_cmath_types; INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_host_basics, eigen_cmath_types, test_specialisation_name); diff --git a/tests/eigen/eigen_eigen.cpp b/tests/eigen/eigen_eigen.cpp index 74a2997f..ddee1a09 100644 --- a/tests/eigen/eigen_eigen.cpp +++ b/tests/eigen/eigen_eigen.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -38,12 +38,14 @@ typedef testing::Types< float, algebra::eigen::point2, algebra::eigen::point3, algebra::eigen::vector2, algebra::eigen::vector3, algebra::eigen::transform3, algebra::eigen::cartesian2, - algebra::eigen::polar2, algebra::eigen::cylindrical2 >, + algebra::eigen::polar2, algebra::eigen::cylindrical2, + std::size_t, algebra::eigen::matrix_type>, test_types< double, algebra::eigen::point2, algebra::eigen::point3, algebra::eigen::vector2, algebra::eigen::vector3, algebra::eigen::transform3, algebra::eigen::cartesian2, - algebra::eigen::polar2, algebra::eigen::cylindrical2 > > + algebra::eigen::polar2, algebra::eigen::cylindrical2, + std::size_t, algebra::eigen::matrix_type> > eigen_eigen_types; INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_host_basics, eigen_eigen_types, test_specialisation_name); diff --git a/tests/smatrix/smatrix_cmath.cpp b/tests/smatrix/smatrix_cmath.cpp index 325d7fa6..70ea8934 100644 --- a/tests/smatrix/smatrix_cmath.cpp +++ b/tests/smatrix/smatrix_cmath.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -39,13 +39,15 @@ typedef testing::Types< algebra::smatrix::vector2, algebra::smatrix::vector3, algebra::smatrix::transform3, algebra::smatrix::cartesian2, algebra::smatrix::polar2, - algebra::smatrix::cylindrical2 >, + algebra::smatrix::cylindrical2, unsigned int, + algebra::smatrix::matrix_type>, test_types< double, algebra::smatrix::point2, algebra::smatrix::point3, algebra::smatrix::vector2, algebra::smatrix::vector3, algebra::smatrix::transform3, algebra::smatrix::cartesian2, algebra::smatrix::polar2, - algebra::smatrix::cylindrical2 > > + algebra::smatrix::cylindrical2, unsigned int, + algebra::smatrix::matrix_type> > smatrix_cmath_types; INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_host_basics, smatrix_cmath_types, test_specialisation_name); diff --git a/tests/smatrix/smatrix_smatrix.cpp b/tests/smatrix/smatrix_smatrix.cpp index 6161609c..d48fa65f 100644 --- a/tests/smatrix/smatrix_smatrix.cpp +++ b/tests/smatrix/smatrix_smatrix.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -39,13 +39,15 @@ typedef testing::Types< algebra::smatrix::vector2, algebra::smatrix::vector3, algebra::smatrix::transform3, algebra::smatrix::cartesian2, algebra::smatrix::polar2, - algebra::smatrix::cylindrical2 >, + algebra::smatrix::cylindrical2, unsigned int, + algebra::smatrix::matrix_type>, test_types< double, algebra::smatrix::point2, algebra::smatrix::point3, algebra::smatrix::vector2, algebra::smatrix::vector3, algebra::smatrix::transform3, algebra::smatrix::cartesian2, algebra::smatrix::polar2, - algebra::smatrix::cylindrical2 > > + algebra::smatrix::cylindrical2, unsigned int, + algebra::smatrix::matrix_type> > smatrix_smatrix_types; INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_host_basics, smatrix_smatrix_types, test_specialisation_name); diff --git a/tests/vc/vc_cmath.cpp b/tests/vc/vc_cmath.cpp index aa1e69b1..7490eeb6 100644 --- a/tests/vc/vc_cmath.cpp +++ b/tests/vc/vc_cmath.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -37,12 +37,13 @@ typedef testing::Types< test_types, algebra::vc::point3, algebra::vc::vector2, algebra::vc::vector3, algebra::vc::transform3, algebra::vc::cartesian2, - algebra::vc::polar2, algebra::vc::cylindrical2 >, + algebra::vc::polar2, algebra::vc::cylindrical2, + std::size_t, algebra::vc::matrix_type>, test_types, algebra::vc::point3, algebra::vc::vector2, algebra::vc::vector3, algebra::vc::transform3, algebra::vc::cartesian2, - algebra::vc::polar2, - algebra::vc::cylindrical2 > > + algebra::vc::polar2, algebra::vc::cylindrical2, + std::size_t, algebra::vc::matrix_type> > vc_cmath_types; INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_host_basics, vc_cmath_types, test_specialisation_name); diff --git a/tests/vc/vc_vc.cpp b/tests/vc/vc_vc.cpp index 11e2ff2c..50ad2443 100644 --- a/tests/vc/vc_vc.cpp +++ b/tests/vc/vc_vc.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -37,12 +37,13 @@ typedef testing::Types< test_types, algebra::vc::point3, algebra::vc::vector2, algebra::vc::vector3, algebra::vc::transform3, algebra::vc::cartesian2, - algebra::vc::polar2, algebra::vc::cylindrical2 >, + algebra::vc::polar2, algebra::vc::cylindrical2, + std::size_t, algebra::vc::matrix_type>, test_types, algebra::vc::point3, algebra::vc::vector2, algebra::vc::vector3, algebra::vc::transform3, algebra::vc::cartesian2, - algebra::vc::polar2, - algebra::vc::cylindrical2 > > + algebra::vc::polar2, algebra::vc::cylindrical2, + std::size_t, algebra::vc::matrix_type> > vc_vc_types; INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_host_basics, vc_vc_types, test_specialisation_name); diff --git a/tests/vecmem/vecmem_cmath.cpp b/tests/vecmem/vecmem_cmath.cpp index c1bb8572..00e781c3 100644 --- a/tests/vecmem/vecmem_cmath.cpp +++ b/tests/vecmem/vecmem_cmath.cpp @@ -1,6 +1,6 @@ /** Algebra plugins library, part of the ACTS project * - * (c) 2020-2021 CERN for the benefit of the ACTS project + * (c) 2020-2022 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -38,13 +38,15 @@ typedef testing::Types< float, algebra::vecmem::point2, algebra::vecmem::point3, algebra::vecmem::vector2, algebra::vecmem::vector3, algebra::vecmem::transform3, algebra::vecmem::cartesian2, - algebra::vecmem::polar2, algebra::vecmem::cylindrical2 >, + algebra::vecmem::polar2, algebra::vecmem::cylindrical2, + std::size_t, algebra::vecmem::matrix_type>, test_types< double, algebra::vecmem::point2, algebra::vecmem::point3, algebra::vecmem::vector2, algebra::vecmem::vector3, algebra::vecmem::transform3, algebra::vecmem::cartesian2, algebra::vecmem::polar2, - algebra::vecmem::cylindrical2 > > + algebra::vecmem::cylindrical2, std::size_t, + algebra::vecmem::matrix_type> > vecmem_cmath_types; INSTANTIATE_TYPED_TEST_SUITE_P(algebra_plugins, test_host_basics, vecmem_cmath_types, test_specialisation_name); From 38a4f60d446bc22d371b8e91c1b21b3204aebc61 Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay Date: Fri, 11 Feb 2022 18:09:13 +0100 Subject: [PATCH 4/5] Made the build work on Windows. --- math/eigen/include/algebra/math/impl/eigen_getter.hpp | 8 ++++---- tests/accelerator/cuda/CMakeLists.txt | 11 ++++++++++- tests/common/test_device_basics.hpp | 4 ++-- tests/common/test_host_basics.hpp | 5 +++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/math/eigen/include/algebra/math/impl/eigen_getter.hpp b/math/eigen/include/algebra/math/impl/eigen_getter.hpp index c70df760..b48047a3 100644 --- a/math/eigen/include/algebra/math/impl/eigen_getter.hpp +++ b/math/eigen/include/algebra/math/impl/eigen_getter.hpp @@ -103,16 +103,16 @@ struct element_getter { Eigen::MatrixBase >::value, bool> = true> ALGEBRA_HOST_DEVICE inline auto &operator()( - Eigen::MatrixBase &m, unsigned int row, - unsigned int col) const { + Eigen::MatrixBase &m, std::size_t row, + std::size_t col) const { return m(row, col); } /// Get const access to a matrix element template ALGEBRA_HOST_DEVICE inline auto operator()( - const Eigen::MatrixBase &m, unsigned int row, - unsigned int col) const { + const Eigen::MatrixBase &m, std::size_t row, + std::size_t col) const { return m(row, col); } diff --git a/tests/accelerator/cuda/CMakeLists.txt b/tests/accelerator/cuda/CMakeLists.txt index 39512c6a..e9f9be18 100644 --- a/tests/accelerator/cuda/CMakeLists.txt +++ b/tests/accelerator/cuda/CMakeLists.txt @@ -1,6 +1,6 @@ # Algebra plugins library, part of the ACTS project (R&D line) # -# (c) 2021 CERN for the benefit of the ACTS project +# (c) 2021-2022 CERN for the benefit of the ACTS project # # Mozilla Public License Version 2.0 @@ -28,6 +28,15 @@ target_compile_options( algebra_tests_cuda_common INTERFACE $<$:-Xcudafe --diag_suppress=177> $<$:--ftz=false --prec-div=true> $<$:--prec-sqrt=true --fmad=false> ) +if( "${CUDAToolkit_VERSION}" VERSION_GREATER_EQUAL "11.5" ) + # Replace all "#pragma diag_suppress" calls in the Eigen code with + # "#pragma nv_diag_suppress" calls. To be removed once the Eigen + # code starts behaving better. Note that this is only needed for + # Windows, as these warnings are suppressed on Linux by declaring + # Eigen as a "system include". + target_compile_definitions( algebra_tests_cuda_common + INTERFACE diag_suppress=nv_diag_suppress ) +endif() add_library( algebra::tests_cuda_common ALIAS algebra_tests_cuda_common ) # Set up all of the (available) CUDA tests. diff --git a/tests/common/test_device_basics.hpp b/tests/common/test_device_basics.hpp index 1f238022..1d90d9e7 100644 --- a/tests/common/test_device_basics.hpp +++ b/tests/common/test_device_basics.hpp @@ -92,8 +92,8 @@ class test_device_basics : public test_base { scalar result = 0.; for (size_type i = 0; i < 6; ++i) { for (size_type j = 0; j < 4; ++j) { - result += 0.6 * algebra::getter::element(m, i, j) + - 0.7 * algebra::getter::element(m2, i, j); + result += 0.6f * algebra::getter::element(m, i, j) + + 0.7f * algebra::getter::element(m2, i, j); } } return result; diff --git a/tests/common/test_host_basics.hpp b/tests/common/test_host_basics.hpp index 6c8b39b7..9ac9776b 100644 --- a/tests/common/test_host_basics.hpp +++ b/tests/common/test_host_basics.hpp @@ -129,8 +129,9 @@ TYPED_TEST_P(test_host_basics, matrix64) { for (typename TypeParam::size_type j = 0; j < COLS; ++j) { const typename TypeParam::scalar ref = static_cast(0.5 * i + j); - EXPECT_FLOAT_EQ(algebra::getter::element(m, i, j), ref); - EXPECT_FLOAT_EQ(algebra::getter::element(m_const_ref, i, j), ref); + ASSERT_NEAR(algebra::getter::element(m, i, j), ref, this->m_epsilon); + ASSERT_NEAR(algebra::getter::element(m_const_ref, i, j), ref, + this->m_epsilon); } } } From 611927dd00db47f90f82ebb7c8ff70697b6197ec Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay Date: Mon, 14 Feb 2022 17:42:50 +0100 Subject: [PATCH 5/5] Moved the element(...) function implementations into the math libraries. Like for most other functions, the frontend libraries now just pull the appropriate function into the algebra::getter namespace. --- .../include/algebra/array_cmath.hpp | 21 ++++-------------- .../include/algebra/eigen_cmath.hpp | 18 ++++----------- .../include/algebra/eigen_eigen.hpp | 18 ++++----------- .../include/algebra/smatrix_cmath.hpp | 19 ++++------------ .../include/algebra/smatrix_smatrix.hpp | 19 ++++------------ .../vc_cmath/include/algebra/vc_cmath.hpp | 19 ++++------------ frontend/vc_vc/include/algebra/vc_vc.hpp | 19 ++++------------ .../include/algebra/vecmem_cmath.hpp | 21 ++++-------------- .../algebra/math/impl/cmath_getter.hpp | 20 +++++++++++++++++ .../algebra/math/impl/eigen_getter.hpp | 22 +++++++++++++++++++ .../algebra/math/impl/smatrix_getter.hpp | 18 +++++++++++++++ 11 files changed, 92 insertions(+), 122 deletions(-) diff --git a/frontend/array_cmath/include/algebra/array_cmath.hpp b/frontend/array_cmath/include/algebra/array_cmath.hpp index 88c220e5..1bc85481 100644 --- a/frontend/array_cmath/include/algebra/array_cmath.hpp +++ b/frontend/array_cmath/include/algebra/array_cmath.hpp @@ -63,25 +63,12 @@ ALGEBRA_HOST_DEVICE inline array::storage_type vector( SIZE>()(m, row, col); } -/// Function extracting an element from a matrix (const) -template -ALGEBRA_HOST_DEVICE inline scalar_t element( - const array::matrix_type& m, std::size_t row, - std::size_t col) { - - return cmath::element_getter()( - m, row, col); -} +/// @name Getter functions on @c algebra::array::matrix_type +/// @{ -/// Function extracting an element from a matrix (non-const) -template -ALGEBRA_HOST_DEVICE inline scalar_t& element( - array::matrix_type& m, std::size_t row, - std::size_t col) { +using cmath::element; - return cmath::element_getter()( - m, row, col); -} +/// @} } // namespace getter diff --git a/frontend/eigen_cmath/include/algebra/eigen_cmath.hpp b/frontend/eigen_cmath/include/algebra/eigen_cmath.hpp index 1e2ef761..e1d53908 100644 --- a/frontend/eigen_cmath/include/algebra/eigen_cmath.hpp +++ b/frontend/eigen_cmath/include/algebra/eigen_cmath.hpp @@ -66,22 +66,12 @@ ALGEBRA_HOST_DEVICE inline auto vector(const Eigen::MatrixBase& m, return m.template block(row, col); } -/// Function extracting an element from a matrix (const) -template -ALGEBRA_HOST_DEVICE inline auto element( - const Eigen::MatrixBase& m, std::size_t row, - std::size_t col) { - - return eigen::math::element_getter()(m, row, col); -} +/// @name Getter functions on @c algebra::eigen::matrix_type +/// @{ -/// Function extracting an element from a matrix (non-const) -template -ALGEBRA_HOST_DEVICE inline auto& element(Eigen::MatrixBase& m, - std::size_t row, std::size_t col) { +using eigen::math::element; - return eigen::math::element_getter()(m, row, col); -} +/// @} } // namespace getter diff --git a/frontend/eigen_eigen/include/algebra/eigen_eigen.hpp b/frontend/eigen_eigen/include/algebra/eigen_eigen.hpp index 9449cd6d..8220c989 100644 --- a/frontend/eigen_eigen/include/algebra/eigen_eigen.hpp +++ b/frontend/eigen_eigen/include/algebra/eigen_eigen.hpp @@ -60,22 +60,12 @@ ALGEBRA_HOST_DEVICE inline auto vector(const Eigen::MatrixBase& m, return m.template block(row, col); } -/// Function extracting an element from a matrix (const) -template -ALGEBRA_HOST_DEVICE inline auto element( - const Eigen::MatrixBase& m, std::size_t row, - std::size_t col) { - - return eigen::math::element_getter()(m, row, col); -} +/// @name Getter functions on @c algebra::eigen::matrix_type +/// @{ -/// Function extracting an element from a matrix (non-const) -template -ALGEBRA_HOST_DEVICE inline auto& element(Eigen::MatrixBase& m, - std::size_t row, std::size_t col) { +using eigen::math::element; - return eigen::math::element_getter()(m, row, col); -} +/// @} } // namespace getter diff --git a/frontend/smatrix_cmath/include/algebra/smatrix_cmath.hpp b/frontend/smatrix_cmath/include/algebra/smatrix_cmath.hpp index 84861f40..16a7a84e 100644 --- a/frontend/smatrix_cmath/include/algebra/smatrix_cmath.hpp +++ b/frontend/smatrix_cmath/include/algebra/smatrix_cmath.hpp @@ -61,23 +61,12 @@ ALGEBRA_HOST_DEVICE inline auto vector( return m.template SubCol >(col, row); } -/// Function extracting an element from a matrix (const) -template -ALGEBRA_HOST_DEVICE inline scalar_t element( - const smatrix::matrix_type& m, std::size_t row, - std::size_t col) { - - return smatrix::math::element_getter()(m, row, col); -} +/// @name Getter functions on @c algebra::smatrix::matrix_type +/// @{ -/// Function extracting an element from a matrix (non-const) -template -ALGEBRA_HOST_DEVICE inline scalar_t& element( - smatrix::matrix_type& m, std::size_t row, - std::size_t col) { +using smatrix::math::element; - return smatrix::math::element_getter()(m, row, col); -} +/// @} } // namespace getter diff --git a/frontend/smatrix_smatrix/include/algebra/smatrix_smatrix.hpp b/frontend/smatrix_smatrix/include/algebra/smatrix_smatrix.hpp index 640cb2ed..c480b002 100644 --- a/frontend/smatrix_smatrix/include/algebra/smatrix_smatrix.hpp +++ b/frontend/smatrix_smatrix/include/algebra/smatrix_smatrix.hpp @@ -54,23 +54,12 @@ ALGEBRA_HOST_DEVICE inline auto vector( return m.template SubCol >(col, row); } -/// Function extracting an element from a matrix (const) -template -ALGEBRA_HOST_DEVICE inline scalar_t element( - const smatrix::matrix_type& m, std::size_t row, - std::size_t col) { - - return smatrix::math::element_getter()(m, row, col); -} +/// @name Getter functions on @c algebra::smatrix::matrix_type +/// @{ -/// Function extracting an element from a matrix (non-const) -template -ALGEBRA_HOST_DEVICE inline scalar_t& element( - smatrix::matrix_type& m, std::size_t row, - std::size_t col) { +using smatrix::math::element; - return smatrix::math::element_getter()(m, row, col); -} +/// @} } // namespace getter diff --git a/frontend/vc_cmath/include/algebra/vc_cmath.hpp b/frontend/vc_cmath/include/algebra/vc_cmath.hpp index 25ffbc87..865ce17a 100644 --- a/frontend/vc_cmath/include/algebra/vc_cmath.hpp +++ b/frontend/vc_cmath/include/algebra/vc_cmath.hpp @@ -81,23 +81,12 @@ ALGEBRA_HOST_DEVICE inline vc::storage_type vector( vc::storage_type >()(m, row, col); } -/// Function extracting an element from a matrix (const) -template -ALGEBRA_HOST_DEVICE inline scalar_t element( - const vc::matrix_type& m, std::size_t row, - std::size_t col) { - - return cmath::element_getter()(m, row, col); -} +/// @name Getter functions on @c algebra::vc::matrix_type +/// @{ -/// Function extracting an element from a matrix (non-const) -template -ALGEBRA_HOST_DEVICE inline scalar_t& element( - vc::matrix_type& m, std::size_t row, - std::size_t col) { +using cmath::element; - return cmath::element_getter()(m, row, col); -} +/// @} } // namespace getter diff --git a/frontend/vc_vc/include/algebra/vc_vc.hpp b/frontend/vc_vc/include/algebra/vc_vc.hpp index e4a5618a..b471b40c 100644 --- a/frontend/vc_vc/include/algebra/vc_vc.hpp +++ b/frontend/vc_vc/include/algebra/vc_vc.hpp @@ -122,23 +122,12 @@ ALGEBRA_HOST_DEVICE inline auto vector( } } -/// Function extracting an element from a matrix (const) -template -ALGEBRA_HOST_DEVICE inline scalar_t element( - const vc::matrix_type& m, std::size_t row, - std::size_t col) { +/// @name Getter functions on @c algebra::vc::matrix_type +/// @{ - return cmath::element_getter()(m, row, col); -} +using cmath::element; -/// Function extracting an element from a matrix (non-const) -template -ALGEBRA_HOST_DEVICE inline scalar_t& element( - vc::matrix_type& m, std::size_t row, - std::size_t col) { - - return cmath::element_getter()(m, row, col); -} +/// @} } // namespace getter diff --git a/frontend/vecmem_cmath/include/algebra/vecmem_cmath.hpp b/frontend/vecmem_cmath/include/algebra/vecmem_cmath.hpp index cb7228f4..5095e1f8 100644 --- a/frontend/vecmem_cmath/include/algebra/vecmem_cmath.hpp +++ b/frontend/vecmem_cmath/include/algebra/vecmem_cmath.hpp @@ -64,25 +64,12 @@ ALGEBRA_HOST_DEVICE inline vecmem::storage_type vector( SIZE>()(m, row, col); } -/// Function extracting an element from a matrix (const) -template -ALGEBRA_HOST_DEVICE inline scalar_t element( - const vecmem::matrix_type& m, std::size_t row, - std::size_t col) { - - return cmath::element_getter()( - m, row, col); -} +/// @name Getter functions on @c algebra::vecmem::matrix_type +/// @{ -/// Function extracting an element from a matrix (non-const) -template -ALGEBRA_HOST_DEVICE inline scalar_t& element( - vecmem::matrix_type& m, std::size_t row, - std::size_t col) { +using cmath::element; - return cmath::element_getter()( - m, row, col); -} +/// @} } // namespace getter diff --git a/math/cmath/include/algebra/math/impl/cmath_getter.hpp b/math/cmath/include/algebra/math/impl/cmath_getter.hpp index ae7f2151..5200306a 100644 --- a/math/cmath/include/algebra/math/impl/cmath_getter.hpp +++ b/math/cmath/include/algebra/math/impl/cmath_getter.hpp @@ -122,6 +122,26 @@ struct element_getter { } }; // struct element_getter +/// Function extracting an element from a matrix (const) +template class array_t, + typename scalar_t, size_type ROWS, size_type COLS> +ALGEBRA_HOST_DEVICE inline scalar_t element( + const array_t, COLS> &m, std::size_t row, + std::size_t col) { + + return element_getter()(m, row, col); +} + +/// Function extracting an element from a matrix (non-const) +template class array_t, + typename scalar_t, size_type ROWS, size_type COLS> +ALGEBRA_HOST_DEVICE inline scalar_t &element( + array_t, COLS> &m, std::size_t row, + std::size_t col) { + + return element_getter()(m, row, col); +} + /// "Vector getter", assuming a simple 2D array access template class array_t, typename scalar_t, size_type SIZE, diff --git a/math/eigen/include/algebra/math/impl/eigen_getter.hpp b/math/eigen/include/algebra/math/impl/eigen_getter.hpp index b48047a3..23d89423 100644 --- a/math/eigen/include/algebra/math/impl/eigen_getter.hpp +++ b/math/eigen/include/algebra/math/impl/eigen_getter.hpp @@ -118,6 +118,28 @@ struct element_getter { } }; // struct element_getter +/// Function extracting an element from a matrix (const) +template +ALGEBRA_HOST_DEVICE inline auto element( + const Eigen::MatrixBase &m, std::size_t row, + std::size_t col) { + + return element_getter()(m, row, col); +} + +/// Function extracting an element from a matrix (non-const) +template < + typename derived_type, + std::enable_if_t, + 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, row, col); +} + /// Functor used to extract a block from Eigen matrices struct block_getter { template diff --git a/math/smatrix/include/algebra/math/impl/smatrix_getter.hpp b/math/smatrix/include/algebra/math/impl/smatrix_getter.hpp index 53df61b4..951969a8 100644 --- a/math/smatrix/include/algebra/math/impl/smatrix_getter.hpp +++ b/math/smatrix/include/algebra/math/impl/smatrix_getter.hpp @@ -146,6 +146,24 @@ struct element_getter { } }; // element_getter +/// 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, + std::size_t col) { + + return element_getter()(m, row, col); +} + +/// 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, + std::size_t col) { + + return element_getter()(m, row, col); +} + /// Functor used to extract a block from SMatrix matrices template struct block_getter {