diff --git a/frontend/array_cmath/include/algebra/array_cmath.hpp b/frontend/array_cmath/include/algebra/array_cmath.hpp index 0d787dfb..6a2ddfef 100644 --- a/frontend/array_cmath/include/algebra/array_cmath.hpp +++ b/frontend/array_cmath/include/algebra/array_cmath.hpp @@ -29,9 +29,10 @@ namespace getter { /// @{ using cmath::storage::block; +using cmath::storage::column; using cmath::storage::element; +using cmath::storage::row; using cmath::storage::set_block; -using cmath::storage::vector; /// @} diff --git a/frontend/eigen_eigen/include/algebra/eigen_eigen.hpp b/frontend/eigen_eigen/include/algebra/eigen_eigen.hpp index 328629a4..dbe6d914 100644 --- a/frontend/eigen_eigen/include/algebra/eigen_eigen.hpp +++ b/frontend/eigen_eigen/include/algebra/eigen_eigen.hpp @@ -28,9 +28,10 @@ namespace getter { /// @{ using eigen::storage::block; +using eigen::storage::column; using eigen::storage::element; +using eigen::storage::row; using eigen::storage::set_block; -using eigen::storage::vector; /// @} diff --git a/frontend/eigen_generic/include/algebra/eigen_generic.hpp b/frontend/eigen_generic/include/algebra/eigen_generic.hpp index 6dfa680d..3415e01c 100644 --- a/frontend/eigen_generic/include/algebra/eigen_generic.hpp +++ b/frontend/eigen_generic/include/algebra/eigen_generic.hpp @@ -32,9 +32,10 @@ namespace getter { /// @{ using eigen::storage::block; +using eigen::storage::column; using eigen::storage::element; +using eigen::storage::row; using eigen::storage::set_block; -using eigen::storage::vector; /// @} diff --git a/frontend/fastor_fastor/include/algebra/fastor_fastor.hpp b/frontend/fastor_fastor/include/algebra/fastor_fastor.hpp index f3621774..4e922826 100644 --- a/frontend/fastor_fastor/include/algebra/fastor_fastor.hpp +++ b/frontend/fastor_fastor/include/algebra/fastor_fastor.hpp @@ -28,9 +28,10 @@ namespace getter { /// @{ using fastor::storage::block; +using fastor::storage::column; using fastor::storage::element; +using fastor::storage::row; using fastor::storage::set_block; -using fastor::storage::vector; /// @} diff --git a/frontend/smatrix_generic/include/algebra/smatrix_generic.hpp b/frontend/smatrix_generic/include/algebra/smatrix_generic.hpp index 7cc40f83..d8da38ec 100644 --- a/frontend/smatrix_generic/include/algebra/smatrix_generic.hpp +++ b/frontend/smatrix_generic/include/algebra/smatrix_generic.hpp @@ -23,9 +23,10 @@ namespace getter { /// @{ using smatrix::storage::block; +using smatrix::storage::column; using smatrix::storage::element; +using smatrix::storage::row; using smatrix::storage::set_block; -using smatrix::storage::vector; /// @} diff --git a/frontend/smatrix_smatrix/include/algebra/smatrix_smatrix.hpp b/frontend/smatrix_smatrix/include/algebra/smatrix_smatrix.hpp index d2d0b099..f2fea243 100644 --- a/frontend/smatrix_smatrix/include/algebra/smatrix_smatrix.hpp +++ b/frontend/smatrix_smatrix/include/algebra/smatrix_smatrix.hpp @@ -19,9 +19,10 @@ namespace getter { /// @{ using smatrix::storage::block; +using smatrix::storage::column; using smatrix::storage::element; +using smatrix::storage::row; using smatrix::storage::set_block; -using smatrix::storage::vector; /// @} diff --git a/frontend/vc_aos/include/algebra/vc_aos.hpp b/frontend/vc_aos/include/algebra/vc_aos.hpp index cfec4604..a723c179 100644 --- a/frontend/vc_aos/include/algebra/vc_aos.hpp +++ b/frontend/vc_aos/include/algebra/vc_aos.hpp @@ -23,9 +23,10 @@ namespace getter { /// @{ using vc_aos::storage::block; +using vc_aos::storage::column; using vc_aos::storage::element; +using vc_aos::storage::row; using vc_aos::storage::set_block; -using vc_aos::storage::vector; /// @} diff --git a/frontend/vc_aos_generic/include/algebra/vc_aos_generic.hpp b/frontend/vc_aos_generic/include/algebra/vc_aos_generic.hpp index d1a94a3d..d2fbbc7a 100644 --- a/frontend/vc_aos_generic/include/algebra/vc_aos_generic.hpp +++ b/frontend/vc_aos_generic/include/algebra/vc_aos_generic.hpp @@ -31,9 +31,10 @@ namespace getter { /// @{ using vc_aos::storage::block; +using vc_aos::storage::column; using vc_aos::storage::element; +using vc_aos::storage::row; using vc_aos::storage::set_block; -using vc_aos::storage::vector; /// @} diff --git a/frontend/vc_soa/include/algebra/vc_soa.hpp b/frontend/vc_soa/include/algebra/vc_soa.hpp index 0a20409e..e7b4e8c0 100644 --- a/frontend/vc_soa/include/algebra/vc_soa.hpp +++ b/frontend/vc_soa/include/algebra/vc_soa.hpp @@ -34,9 +34,10 @@ namespace getter { /// @{ using vc_soa::storage::block; +using vc_soa::storage::column; using vc_soa::storage::element; +using vc_soa::storage::row; using vc_soa::storage::set_block; -using vc_soa::storage::vector; /// @} diff --git a/frontend/vecmem_cmath/include/algebra/vecmem_cmath.hpp b/frontend/vecmem_cmath/include/algebra/vecmem_cmath.hpp index daf11920..359b566d 100644 --- a/frontend/vecmem_cmath/include/algebra/vecmem_cmath.hpp +++ b/frontend/vecmem_cmath/include/algebra/vecmem_cmath.hpp @@ -29,9 +29,10 @@ namespace getter { /// @{ using cmath::storage::block; +using cmath::storage::column; using cmath::storage::element; +using cmath::storage::row; using cmath::storage::set_block; -using cmath::storage::vector; /// @} diff --git a/storage/cmath/include/algebra/storage/impl/cmath_getter.hpp b/storage/cmath/include/algebra/storage/impl/cmath_getter.hpp index 79ddd6d7..b857fd60 100644 --- a/storage/cmath/include/algebra/storage/impl/cmath_getter.hpp +++ b/storage/cmath/include/algebra/storage/impl/cmath_getter.hpp @@ -165,11 +165,31 @@ struct block_getter { return submatrix; } - /// Operator producing a vector out of a const matrix + /// Operator producing a row vector out of a const matrix template class array_t> - ALGEBRA_HOST_DEVICE inline array_t vector( + ALGEBRA_HOST_DEVICE inline array_t row( + const array_t, COLS> &m, std::size_t row, + std::size_t col) { + + assert(col + SIZE <= COLS); + assert(row < ROWS); + + array_t subvector{}; + + for (std::size_t icol = col; icol < col + SIZE; ++icol) { + subvector[icol - col] = m[icol][row]; + } + + return subvector; + } + + /// Operator producing a column vector out of a const matrix + template class array_t> + ALGEBRA_HOST_DEVICE inline array_t column( const array_t, COLS> &m, std::size_t row, std::size_t col) { @@ -196,15 +216,26 @@ ALGEBRA_HOST_DEVICE decltype(auto) block(const input_matrix_type &m, return block_getter().template operator()(m, row, col); } -/// Function extracting a vector from a matrix +/// Function extracting a row vector from a matrix +template class array_t> +ALGEBRA_HOST_DEVICE inline array_t row( + const array_t, COLS> &m, std::size_t row, + std::size_t col) { + + return block_getter().template row(m, row, col); +} + +/// Function extracting a column vector from a matrix template class array_t> -ALGEBRA_HOST_DEVICE inline array_t vector( +ALGEBRA_HOST_DEVICE inline array_t column( const array_t, COLS> &m, std::size_t row, std::size_t col) { - return block_getter().template vector(m, row, col); + return block_getter().template column(m, row, col); } /// Sets a matrix of dimension @tparam ROW and @tparam COL as submatrix of diff --git a/storage/common/include/algebra/storage/matrix_getter.hpp b/storage/common/include/algebra/storage/matrix_getter.hpp index 5ac91568..8eeee2ee 100644 --- a/storage/common/include/algebra/storage/matrix_getter.hpp +++ b/storage/common/include/algebra/storage/matrix_getter.hpp @@ -178,18 +178,42 @@ struct block_getter { return res_m; } - /// Get a vector of a const matrix + /// Get a row vector of a const matrix template class array_t> - ALGEBRA_HOST_DEVICE constexpr auto vector( + ALGEBRA_HOST_DEVICE constexpr auto row( + const matrix &m, const std::size_t row, + const std::size_t col) noexcept { + + static_assert(SIZE <= ROWS); + static_assert(SIZE <= COLS); + assert(row < ROWS); + assert(col + SIZE <= COLS); + + using vector_t = algebra::storage::vector; + + vector_t res_v{}; + + for (std::size_t i = col; i < col + SIZE; ++i) { + res_v[i - col] = m[i][row]; + } + + return res_v; + } + + /// Get a column vector of a const matrix + template class array_t> + ALGEBRA_HOST_DEVICE constexpr auto column( const matrix &m, const std::size_t row, const std::size_t col) noexcept { static_assert(SIZE <= ROWS); static_assert(SIZE <= COLS); assert(row + SIZE <= ROWS); - assert(col <= COLS); + assert(col < COLS); using input_matrix_t = matrix; using vector_t = algebra::storage::vector; @@ -283,4 +307,22 @@ ALGEBRA_HOST_DEVICE constexpr void set_block( } } +template class array_t> +ALGEBRA_HOST_DEVICE constexpr auto row( + const algebra::storage::matrix &m, + const std::size_t row, const std::size_t col) noexcept { + return algebra::storage::block_getter{}.template row(m, row, col); +} + +template class array_t> +ALGEBRA_HOST_DEVICE constexpr auto column( + const algebra::storage::matrix &m, + const std::size_t row, const std::size_t col) noexcept { + return algebra::storage::block_getter{}.template column(m, row, col); +} + } // namespace algebra::storage diff --git a/storage/eigen/include/algebra/storage/impl/eigen_getter.hpp b/storage/eigen/include/algebra/storage/impl/eigen_getter.hpp index 58a5493a..4f193171 100644 --- a/storage/eigen/include/algebra/storage/impl/eigen_getter.hpp +++ b/storage/eigen/include/algebra/storage/impl/eigen_getter.hpp @@ -38,12 +38,12 @@ struct element_getter { /// Get non-const access to a matrix element template - requires std::is_base_of_v< - Eigen::DenseCoeffsBase, - Eigen::MatrixBase > - ALGEBRA_HOST_DEVICE inline auto &operator()( - Eigen::MatrixBase &m, size_type_1 row, - size_type_2 col) const { + requires std::is_base_of_v< + Eigen::DenseCoeffsBase, + Eigen::MatrixBase > + 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)); } @@ -58,11 +58,11 @@ struct element_getter { } /// Get non-const access to a matrix element template - requires std::is_base_of_v< - Eigen::DenseCoeffsBase, - Eigen::MatrixBase > - ALGEBRA_HOST_DEVICE inline auto &operator()( - Eigen::MatrixBase &m, size_type row) const { + requires std::is_base_of_v< + Eigen::DenseCoeffsBase, + Eigen::MatrixBase > + ALGEBRA_HOST_DEVICE inline auto &operator()( + Eigen::MatrixBase &m, size_type row) const { return m(static_cast(row)); } @@ -87,11 +87,11 @@ ALGEBRA_HOST_DEVICE inline decltype(auto) element( /// Function extracting an element from a matrix (non-const) template -requires std::is_base_of_v< - Eigen::DenseCoeffsBase, - Eigen::MatrixBase > - ALGEBRA_HOST_DEVICE inline decltype(auto) element( - Eigen::MatrixBase &m, std::size_t row, std::size_t col) { + requires std::is_base_of_v< + Eigen::DenseCoeffsBase, + Eigen::MatrixBase > +ALGEBRA_HOST_DEVICE inline decltype(auto) element( + Eigen::MatrixBase &m, std::size_t row, std::size_t col) { return element_getter()(m, static_cast(row), static_cast(col)); @@ -107,11 +107,11 @@ ALGEBRA_HOST_DEVICE inline decltype(auto) element( /// Function extracting an element from a matrix (non-const) template -requires std::is_base_of_v< - Eigen::DenseCoeffsBase, - Eigen::MatrixBase > - ALGEBRA_HOST_DEVICE inline decltype(auto) element( - Eigen::MatrixBase &m, std::size_t row) { + requires std::is_base_of_v< + Eigen::DenseCoeffsBase, + Eigen::MatrixBase > +ALGEBRA_HOST_DEVICE inline decltype(auto) element( + Eigen::MatrixBase &m, std::size_t row) { return element_getter()(m, static_cast(row)); } @@ -139,7 +139,25 @@ struct block_getter { template - ALGEBRA_HOST_DEVICE decltype(auto) vector(Eigen::MatrixBase &m, + ALGEBRA_HOST_DEVICE decltype(auto) row(Eigen::MatrixBase &m, + size_type_1 row, + size_type_2 col) const { + + return m.template block<1, SIZE>(row, col); + } + + template + ALGEBRA_HOST_DEVICE decltype(auto) row( + const Eigen::MatrixBase &m, size_type_1 row, + size_type_2 col) const { + + return m.template block<1, SIZE>(row, col); + } + + template + ALGEBRA_HOST_DEVICE decltype(auto) column(Eigen::MatrixBase &m, size_type_1 row, size_type_2 col) const { @@ -148,7 +166,7 @@ struct block_getter { template - ALGEBRA_HOST_DEVICE decltype(auto) vector( + ALGEBRA_HOST_DEVICE decltype(auto) column( const Eigen::MatrixBase &m, size_type_1 row, size_type_2 col) const { @@ -176,11 +194,21 @@ ALGEBRA_HOST_DEVICE decltype(auto) block(Eigen::MatrixBase &m, /// Function extracting a slice from the matrix template -ALGEBRA_HOST_DEVICE inline decltype(auto) vector( +ALGEBRA_HOST_DEVICE inline decltype(auto) row( + const Eigen::MatrixBase &m, std::size_t row, + std::size_t col) { + + return block_getter{}.template row(m, static_cast(row), + static_cast(col)); +} + +/// Function extracting a slice from the matrix +template +ALGEBRA_HOST_DEVICE inline decltype(auto) column( const Eigen::MatrixBase &m, std::size_t row, std::size_t col) { - return block_getter{}.template vector(m, static_cast(row), + return block_getter{}.template column(m, static_cast(row), static_cast(col)); } diff --git a/storage/fastor/include/algebra/storage/impl/fastor_getter.hpp b/storage/fastor/include/algebra/storage/impl/fastor_getter.hpp index c01f45c7..e1cb0c60 100644 --- a/storage/fastor/include/algebra/storage/impl/fastor_getter.hpp +++ b/storage/fastor/include/algebra/storage/impl/fastor_getter.hpp @@ -143,7 +143,18 @@ struct block_getter { template - ALGEBRA_HOST_DEVICE Fastor::Tensor vector( + ALGEBRA_HOST_DEVICE Fastor::Tensor row( + const Fastor::Tensor &m, std::size_t row, + std::size_t col) const { + + return Fastor::Tensor( + m(static_cast(row), + Fastor::seq(static_cast(col), static_cast(col + SIZE)))); + } + + template + ALGEBRA_HOST_DEVICE Fastor::Tensor column( const Fastor::Tensor &m, std::size_t row, std::size_t col) const { @@ -163,14 +174,24 @@ ALGEBRA_HOST_DEVICE decltype(auto) block( return block_getter{}.template operator()(m, row, col); } -/// Function extracting a slice from the matrix +/// Function extracting a row vector from the matrix +template +ALGEBRA_HOST_DEVICE inline decltype(auto) row( + const Fastor::Tensor &m, std::size_t row, + std::size_t col) { + + return block_getter{}.template row(m, row, col); +} + +/// Function extracting a column vector from the matrix template -ALGEBRA_HOST_DEVICE inline decltype(auto) vector( +ALGEBRA_HOST_DEVICE inline decltype(auto) column( const Fastor::Tensor &m, std::size_t row, std::size_t col) { - return block_getter{}.template vector(m, row, col); + return block_getter{}.template column(m, row, col); } /// Operator setting a block with a matrix diff --git a/storage/smatrix/include/algebra/storage/impl/smatrix_getter.hpp b/storage/smatrix/include/algebra/storage/impl/smatrix_getter.hpp index 8433779f..456497ad 100644 --- a/storage/smatrix/include/algebra/storage/impl/smatrix_getter.hpp +++ b/storage/smatrix/include/algebra/storage/impl/smatrix_getter.hpp @@ -133,7 +133,16 @@ struct block_getter { template - ALGEBRA_HOST_DEVICE ROOT::Math::SVector vector( + ALGEBRA_HOST_DEVICE ROOT::Math::SVector column( + const ROOT::Math::SMatrix &m, unsigned int row, + unsigned int col) const { + + return m.template SubRow>(row, col); + } + + template + ALGEBRA_HOST_DEVICE ROOT::Math::SVector column( const ROOT::Math::SMatrix &m, unsigned int row, unsigned int col) const { @@ -167,11 +176,23 @@ ALGEBRA_HOST_DEVICE ROOT::Math::SMatrix block( /// @c algebra::smatrix::transform3 template -ALGEBRA_HOST_DEVICE inline auto vector( +ALGEBRA_HOST_DEVICE inline auto row( + const ROOT::Math::SMatrix &m, std::size_t row, + std::size_t col) { + + return block_getter{}.template row(m, static_cast(row), + static_cast(col)); +} + +/// Function extracting a slice from the matrix used by +/// @c algebra::smatrix::transform3 +template +ALGEBRA_HOST_DEVICE inline auto column( const ROOT::Math::SMatrix &m, std::size_t row, std::size_t col) { - return block_getter{}.template vector(m, static_cast(row), + return block_getter{}.template column(m, static_cast(row), static_cast(col)); } 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 3bc7bbb2..f5d33f24 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 @@ -15,17 +15,29 @@ namespace algebra::vc_aos::storage { using algebra::storage::block; +using algebra::storage::column; using algebra::storage::element; +using algebra::storage::row; using algebra::storage::set_block; -/// Get a vector of a const matrix -template class array_t> -ALGEBRA_HOST_DEVICE constexpr decltype(auto) vector( +ALGEBRA_HOST_DEVICE constexpr decltype(auto) row( const algebra::storage::matrix &m, const std::size_t row, const std::size_t col) noexcept { - return algebra::storage::block_getter{}.template vector(m, row, col); + return algebra::storage::block_getter{}.template row(m, row, col); } +/// Get a column vector of a const matrix +template class array_t> +ALGEBRA_HOST_DEVICE constexpr decltype(auto) column( + const algebra::storage::matrix &m, + const std::size_t row, const std::size_t col) noexcept { + return algebra::storage::block_getter{}.template column(m, row, col); +}*/ + } // namespace algebra::vc_aos::storage 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 98cf14ee..ac0d40a8 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 @@ -15,17 +15,19 @@ namespace algebra::vc_soa::storage { using algebra::storage::block; +using algebra::storage::column; using algebra::storage::element; +using algebra::storage::row; using algebra::storage::set_block; /// Get a vector of a const matrix -template class array_t> -ALGEBRA_HOST_DEVICE constexpr auto vector( +ALGEBRA_HOST_DEVICE constexpr auto column( const algebra::storage::matrix &m, const std::size_t row, const std::size_t col) noexcept { - return algebra::storage::block_getter{}.template vector(m, row, col); -} + return algebra::storage::block_getter{}.template column(m, row, col); +}*/ } // namespace algebra::vc_soa::storage diff --git a/tests/common/test_host_basics.hpp b/tests/common/test_host_basics.hpp index 72282212..6fcf3d9a 100644 --- a/tests/common/test_host_basics.hpp +++ b/tests/common/test_host_basics.hpp @@ -724,17 +724,17 @@ TYPED_TEST_P(test_host_basics_transform, transform3) { test_vector; // we need to declare a variable in order to use the // [[maybe_unused]] attribute here - test_vector = algebra::getter::vector<3>(m44, 0, 0); - test_vector = algebra::getter::vector<3>(m44, 0, 1); - test_vector = algebra::getter::vector<3>(m44, 0, 2); + test_vector = algebra::getter::column<3>(m44, 0, 0); + test_vector = algebra::getter::column<3>(m44, 0, 1); + test_vector = algebra::getter::column<3>(m44, 0, 2); // Test constructor from inverse matrix auto m44_inv = trf2.matrix_inverse(); // Make sure that algebra::getter:vector can be called. - test_vector = algebra::getter::vector<3>(m44_inv, 0, 0); - test_vector = algebra::getter::vector<3>(m44_inv, 0, 1); - test_vector = algebra::getter::vector<3>(m44_inv, 0, 2); + test_vector = algebra::getter::column<3>(m44_inv, 0, 0); + test_vector = algebra::getter::column<3>(m44_inv, 0, 1); + test_vector = algebra::getter::column<3>(m44_inv, 0, 2); // Re-evaluate rot and trn auto rotm = trfm.rotation();