Skip to content

Commit

Permalink
Moved the element(...) function implementations into the math libraries.
Browse files Browse the repository at this point in the history
Like for most other functions, the frontend libraries now just pull the
appropriate function into the algebra::getter namespace.
  • Loading branch information
krasznaa committed Feb 14, 2022
1 parent 38a4f60 commit 611927d
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 122 deletions.
21 changes: 4 additions & 17 deletions frontend/array_cmath/include/algebra/array_cmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,12 @@ ALGEBRA_HOST_DEVICE inline array::storage_type<scalar_t, SIZE> vector(
SIZE>()(m, row, col);
}

/// Function extracting an element from a matrix (const)
template <typename scalar_t, std::size_t ROWS, std::size_t COLS>
ALGEBRA_HOST_DEVICE inline scalar_t element(
const array::matrix_type<scalar_t, ROWS, COLS>& m, std::size_t row,
std::size_t col) {

return cmath::element_getter<std::size_t, array::storage_type, scalar_t>()(
m, row, col);
}
/// @name Getter functions on @c algebra::array::matrix_type
/// @{

/// Function extracting an element from a matrix (non-const)
template <typename scalar_t, std::size_t ROWS, std::size_t COLS>
ALGEBRA_HOST_DEVICE inline scalar_t& element(
array::matrix_type<scalar_t, ROWS, COLS>& m, std::size_t row,
std::size_t col) {
using cmath::element;

return cmath::element_getter<std::size_t, array::storage_type, scalar_t>()(
m, row, col);
}
/// @}

} // namespace getter

Expand Down
18 changes: 4 additions & 14 deletions frontend/eigen_cmath/include/algebra/eigen_cmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,12 @@ ALGEBRA_HOST_DEVICE inline auto vector(const Eigen::MatrixBase<derived_type>& m,
return m.template block<SIZE, 1>(row, col);
}

/// Function extracting an element from a matrix (const)
template <typename derived_type>
ALGEBRA_HOST_DEVICE inline auto element(
const Eigen::MatrixBase<derived_type>& 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 <typename derived_type>
ALGEBRA_HOST_DEVICE inline auto& element(Eigen::MatrixBase<derived_type>& m,
std::size_t row, std::size_t col) {
using eigen::math::element;

return eigen::math::element_getter()(m, row, col);
}
/// @}

} // namespace getter

Expand Down
18 changes: 4 additions & 14 deletions frontend/eigen_eigen/include/algebra/eigen_eigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,12 @@ ALGEBRA_HOST_DEVICE inline auto vector(const Eigen::MatrixBase<derived_type>& m,
return m.template block<SIZE, 1>(row, col);
}

/// Function extracting an element from a matrix (const)
template <typename derived_type>
ALGEBRA_HOST_DEVICE inline auto element(
const Eigen::MatrixBase<derived_type>& 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 <typename derived_type>
ALGEBRA_HOST_DEVICE inline auto& element(Eigen::MatrixBase<derived_type>& m,
std::size_t row, std::size_t col) {
using eigen::math::element;

return eigen::math::element_getter()(m, row, col);
}
/// @}

} // namespace getter

Expand Down
19 changes: 4 additions & 15 deletions frontend/smatrix_cmath/include/algebra/smatrix_cmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,12 @@ ALGEBRA_HOST_DEVICE inline auto vector(
return m.template SubCol<smatrix::storage_type<scalar_t, SIZE> >(col, row);
}

/// Function extracting an element from a matrix (const)
template <typename scalar_t, unsigned int ROWS, unsigned int COLS>
ALGEBRA_HOST_DEVICE inline scalar_t element(
const smatrix::matrix_type<scalar_t, ROWS, COLS>& m, std::size_t row,
std::size_t col) {

return smatrix::math::element_getter<scalar_t>()(m, row, col);
}
/// @name Getter functions on @c algebra::smatrix::matrix_type
/// @{

/// Function extracting an element from a matrix (non-const)
template <typename scalar_t, unsigned int ROWS, unsigned int COLS>
ALGEBRA_HOST_DEVICE inline scalar_t& element(
smatrix::matrix_type<scalar_t, ROWS, COLS>& m, std::size_t row,
std::size_t col) {
using smatrix::math::element;

return smatrix::math::element_getter<scalar_t>()(m, row, col);
}
/// @}

} // namespace getter

Expand Down
19 changes: 4 additions & 15 deletions frontend/smatrix_smatrix/include/algebra/smatrix_smatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,12 @@ ALGEBRA_HOST_DEVICE inline auto vector(
return m.template SubCol<smatrix::storage_type<scalar_t, SIZE> >(col, row);
}

/// Function extracting an element from a matrix (const)
template <typename scalar_t, unsigned int ROWS, unsigned int COLS>
ALGEBRA_HOST_DEVICE inline scalar_t element(
const smatrix::matrix_type<scalar_t, ROWS, COLS>& m, std::size_t row,
std::size_t col) {

return smatrix::math::element_getter<scalar_t>()(m, row, col);
}
/// @name Getter functions on @c algebra::smatrix::matrix_type
/// @{

/// Function extracting an element from a matrix (non-const)
template <typename scalar_t, unsigned int ROWS, unsigned int COLS>
ALGEBRA_HOST_DEVICE inline scalar_t& element(
smatrix::matrix_type<scalar_t, ROWS, COLS>& m, std::size_t row,
std::size_t col) {
using smatrix::math::element;

return smatrix::math::element_getter<scalar_t>()(m, row, col);
}
/// @}

} // namespace getter

Expand Down
19 changes: 4 additions & 15 deletions frontend/vc_cmath/include/algebra/vc_cmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,12 @@ ALGEBRA_HOST_DEVICE inline vc::storage_type<scalar_t, SIZE> vector(
vc::storage_type<scalar_t, SIZE> >()(m, row, col);
}

/// Function extracting an element from a matrix (const)
template <typename scalar_t, std::size_t ROWS, std::size_t COLS>
ALGEBRA_HOST_DEVICE inline scalar_t element(
const vc::matrix_type<scalar_t, ROWS, COLS>& m, std::size_t row,
std::size_t col) {

return cmath::element_getter<std::size_t, Vc::array, scalar_t>()(m, row, col);
}
/// @name Getter functions on @c algebra::vc::matrix_type
/// @{

/// Function extracting an element from a matrix (non-const)
template <typename scalar_t, std::size_t ROWS, std::size_t COLS>
ALGEBRA_HOST_DEVICE inline scalar_t& element(
vc::matrix_type<scalar_t, ROWS, COLS>& m, std::size_t row,
std::size_t col) {
using cmath::element;

return cmath::element_getter<std::size_t, Vc::array, scalar_t>()(m, row, col);
}
/// @}

} // namespace getter

Expand Down
19 changes: 4 additions & 15 deletions frontend/vc_vc/include/algebra/vc_vc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,12 @@ ALGEBRA_HOST_DEVICE inline auto vector(
}
}

/// Function extracting an element from a matrix (const)
template <typename scalar_t, std::size_t ROWS, std::size_t COLS>
ALGEBRA_HOST_DEVICE inline scalar_t element(
const vc::matrix_type<scalar_t, ROWS, COLS>& m, std::size_t row,
std::size_t col) {
/// @name Getter functions on @c algebra::vc::matrix_type
/// @{

return cmath::element_getter<std::size_t, Vc::array, scalar_t>()(m, row, col);
}
using cmath::element;

/// Function extracting an element from a matrix (non-const)
template <typename scalar_t, std::size_t ROWS, std::size_t COLS>
ALGEBRA_HOST_DEVICE inline scalar_t& element(
vc::matrix_type<scalar_t, ROWS, COLS>& m, std::size_t row,
std::size_t col) {

return cmath::element_getter<std::size_t, Vc::array, scalar_t>()(m, row, col);
}
/// @}

} // namespace getter

Expand Down
21 changes: 4 additions & 17 deletions frontend/vecmem_cmath/include/algebra/vecmem_cmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,12 @@ ALGEBRA_HOST_DEVICE inline vecmem::storage_type<scalar_t, SIZE> vector(
SIZE>()(m, row, col);
}

/// Function extracting an element from a matrix (const)
template <typename scalar_t, std::size_t ROWS, std::size_t COLS>
ALGEBRA_HOST_DEVICE inline scalar_t element(
const vecmem::matrix_type<scalar_t, ROWS, COLS>& m, std::size_t row,
std::size_t col) {

return cmath::element_getter<std::size_t, vecmem::storage_type, scalar_t>()(
m, row, col);
}
/// @name Getter functions on @c algebra::vecmem::matrix_type
/// @{

/// Function extracting an element from a matrix (non-const)
template <typename scalar_t, std::size_t ROWS, std::size_t COLS>
ALGEBRA_HOST_DEVICE inline scalar_t& element(
vecmem::matrix_type<scalar_t, ROWS, COLS>& m, std::size_t row,
std::size_t col) {
using cmath::element;

return cmath::element_getter<std::size_t, vecmem::storage_type, scalar_t>()(
m, row, col);
}
/// @}

} // namespace getter

Expand Down
20 changes: 20 additions & 0 deletions math/cmath/include/algebra/math/impl/cmath_getter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,26 @@ struct element_getter {
}
}; // struct element_getter

/// Function extracting an element from a matrix (const)
template <typename size_type, template <typename, size_type> class array_t,
typename scalar_t, size_type ROWS, size_type COLS>
ALGEBRA_HOST_DEVICE inline scalar_t element(
const array_t<array_t<scalar_t, ROWS>, COLS> &m, std::size_t row,
std::size_t col) {

return element_getter<size_type, array_t, scalar_t>()(m, row, col);
}

/// Function extracting an element from a matrix (non-const)
template <typename size_type, template <typename, size_type> class array_t,
typename scalar_t, size_type ROWS, size_type COLS>
ALGEBRA_HOST_DEVICE inline scalar_t &element(
array_t<array_t<scalar_t, ROWS>, COLS> &m, std::size_t row,
std::size_t col) {

return element_getter<size_type, array_t, scalar_t>()(m, row, col);
}

/// "Vector getter", assuming a simple 2D array access
template <typename size_type, template <typename, size_type> class array_t,
typename scalar_t, size_type SIZE,
Expand Down
22 changes: 22 additions & 0 deletions math/eigen/include/algebra/math/impl/eigen_getter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,28 @@ struct element_getter {
}
}; // struct element_getter

/// Function extracting an element from a matrix (const)
template <typename derived_type>
ALGEBRA_HOST_DEVICE inline auto element(
const Eigen::MatrixBase<derived_type> &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<std::is_base_of<Eigen::DenseCoeffsBase<
derived_type, Eigen::WriteAccessors>,
Eigen::MatrixBase<derived_type> >::value,
bool> = true>
ALGEBRA_HOST_DEVICE inline auto &element(Eigen::MatrixBase<derived_type> &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 <std::size_t kROWS, std::size_t kCOLS, typename matrix_type>
Expand Down
18 changes: 18 additions & 0 deletions math/smatrix/include/algebra/math/impl/smatrix_getter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,24 @@ struct element_getter {
}
}; // element_getter

/// Function extracting an element from a matrix (const)
template <typename scalar_t, unsigned int ROWS, unsigned int COLS>
ALGEBRA_HOST_DEVICE inline scalar_t element(
const ROOT::Math::SMatrix<scalar_t, ROWS, COLS> &m, std::size_t row,
std::size_t col) {

return element_getter<scalar_t>()(m, row, col);
}

/// Function extracting an element from a matrix (non-const)
template <typename scalar_t, unsigned int ROWS, unsigned int COLS>
ALGEBRA_HOST_DEVICE inline scalar_t &element(
ROOT::Math::SMatrix<scalar_t, ROWS, COLS> &m, std::size_t row,
std::size_t col) {

return element_getter<scalar_t>()(m, row, col);
}

/// Functor used to extract a block from SMatrix matrices
template <typename scalar_t>
struct block_getter {
Expand Down

0 comments on commit 611927d

Please sign in to comment.