From 0af2f754254281b754e4a7893dc1aeb0ab8b7489 Mon Sep 17 00:00:00 2001 From: Joana Niermann Date: Tue, 30 Dec 2025 16:13:33 +0100 Subject: [PATCH] Move algebra plugins to detray code --- core/include/detray/algebra/concepts.hpp | 168 +++++++++ .../detray/algebra/frontend/CMakeLists.txt | 32 ++ .../algebra/frontend/cmath/CMakeLists.txt | 13 + .../frontend/cmath/include/algebra/cmath.hpp | 153 ++++++++ .../algebra/frontend/eigen/CMakeLists.txt | 14 + .../frontend/eigen/include/algebra/eigen.hpp | 116 ++++++ .../algebra/frontend/fastor/CMakeLists.txt | 13 + .../fastor/include/algebra/fastor.hpp | 123 ++++++ .../algebra/frontend/smatrix/CMakeLists.txt | 13 + .../smatrix/include/algebra/smatrix.hpp | 114 ++++++ .../algebra/frontend/vc_aos/CMakeLists.txt | 13 + .../vc_aos/include/algebra/vc_aos.hpp | 141 +++++++ .../algebra/frontend/vc_soa/CMakeLists.txt | 14 + .../vc_soa/include/algebra/vc_soa.hpp | 131 +++++++ .../detray/algebra/math/CMakeLists.txt | 23 ++ .../detray/algebra/math/cmath/CMakeLists.txt | 17 + .../math/cmath/include/algebra/math/cmath.hpp | 15 + .../algebra/math/impl/cmath_matrix.hpp | 86 +++++ .../algebra/math/impl/cmath_operators.hpp | 215 +++++++++++ .../algebra/math/impl/cmath_vector.hpp | 208 ++++++++++ .../detray/algebra/math/common/CMakeLists.txt | 16 + .../common/include/algebra/math/boolean.hpp | 25 ++ .../common/include/algebra/math/common.hpp | 32 ++ .../detray/algebra/math/eigen/CMakeLists.txt | 17 + .../math/eigen/include/algebra/math/eigen.hpp | 16 + .../algebra/math/impl/eigen_matrix.hpp | 86 +++++ .../algebra/math/impl/eigen_transform3.hpp | 284 ++++++++++++++ .../algebra/math/impl/eigen_vector.hpp | 115 ++++++ .../detray/algebra/math/fastor/CMakeLists.txt | 17 + .../fastor/include/algebra/math/fastor.hpp | 15 + .../algebra/math/impl/fastor_matrix.hpp | 90 +++++ .../algebra/math/impl/fastor_transform3.hpp | 252 +++++++++++++ .../algebra/math/impl/fastor_vector.hpp | 252 +++++++++++++ .../algebra/math/generic/CMakeLists.txt | 26 ++ .../decomposition/partial_pivot_lud.hpp | 123 ++++++ .../matrix/determinant/cofactor.hpp | 105 ++++++ .../matrix/determinant/hard_coded.hpp | 97 +++++ .../matrix/determinant/partial_pivot_lud.hpp | 55 +++ .../algorithms/matrix/inverse/cofactor.hpp | 137 +++++++ .../algorithms/matrix/inverse/hard_coded.hpp | 276 ++++++++++++++ .../matrix/inverse/partial_pivot_lud.hpp | 74 ++++ .../algorithms/utils/algorithm_finder.hpp | 60 +++ .../generic/include/algebra/math/generic.hpp | 25 ++ .../algebra/math/impl/generic_matrix.hpp | 341 +++++++++++++++++ .../algebra/math/impl/generic_transform3.hpp | 341 +++++++++++++++++ .../algebra/math/impl/generic_vector.hpp | 152 ++++++++ .../algebra/math/smatrix/CMakeLists.txt | 21 ++ .../algebra/math/impl/smatrix_errorcheck.hpp | 21 ++ .../algebra/math/impl/smatrix_matrix.hpp | 73 ++++ .../algebra/math/impl/smatrix_transform3.hpp | 270 +++++++++++++ .../algebra/math/impl/smatrix_vector.hpp | 338 +++++++++++++++++ .../smatrix/include/algebra/math/smatrix.hpp | 15 + .../detray/algebra/math/vc_aos/CMakeLists.txt | 16 + .../algebra/math/impl/vc_aos_matrix.hpp | 48 +++ .../algebra/math/impl/vc_aos_transform3.hpp | 354 ++++++++++++++++++ .../algebra/math/impl/vc_aos_vector.hpp | 162 ++++++++ .../vc_aos/include/algebra/math/vc_aos.hpp | 15 + .../detray/algebra/math/vc_soa/CMakeLists.txt | 17 + .../algebra/math/impl/vc_soa_boolean.hpp | 49 +++ .../include/algebra/math/impl/vc_soa_math.hpp | 138 +++++++ .../algebra/math/impl/vc_soa_matrix.hpp | 40 ++ .../algebra/math/impl/vc_soa_vector.hpp | 202 ++++++++++ .../vc_soa/include/algebra/math/vc_soa.hpp | 14 + .../detray/algebra/storage/CMakeLists.txt | 26 ++ .../algebra/storage/array/CMakeLists.txt | 13 + .../array/include/algebra/storage/array.hpp | 63 ++++ .../algebra/storage/cmath/CMakeLists.txt | 13 + .../algebra/storage/impl/cmath_getter.hpp | 239 ++++++++++++ .../algebra/storage/common/CMakeLists.txt | 13 + .../algebra/storage/array_operators.hpp | 100 +++++ .../common/include/algebra/storage/matrix.hpp | 328 ++++++++++++++++ .../include/algebra/storage/matrix_getter.hpp | 286 ++++++++++++++ .../common/include/algebra/storage/vector.hpp | 296 +++++++++++++++ .../algebra/storage/eigen/CMakeLists.txt | 15 + .../eigen/include/algebra/storage/eigen.hpp | 184 +++++++++ .../algebra/storage/impl/eigen_array.hpp | 44 +++ .../algebra/storage/impl/eigen_getter.hpp | 199 ++++++++++ .../algebra/storage/fastor/CMakeLists.txt | 15 + .../fastor/include/algebra/storage/fastor.hpp | 63 ++++ .../algebra/storage/impl/fastor_getter.hpp | 196 ++++++++++ .../algebra/storage/impl/fastor_matrix.hpp | 85 +++++ .../algebra/storage/smatrix/CMakeLists.txt | 17 + .../algebra/storage/impl/smatrix_getter.hpp | 203 ++++++++++ .../include/algebra/storage/smatrix.hpp | 66 ++++ .../algebra/storage/vc_aos/CMakeLists.txt | 16 + .../impl/vc_aos_approximately_equal.hpp | 73 ++++ .../algebra/storage/impl/vc_aos_concepts.hpp | 39 ++ .../algebra/storage/impl/vc_aos_getter.hpp | 31 ++ .../vc_aos/include/algebra/storage/vc_aos.hpp | 134 +++++++ .../algebra/storage/vc_soa/CMakeLists.txt | 16 + .../algebra/storage/impl/vc_soa_casts.hpp | 49 +++ .../algebra/storage/impl/vc_soa_concepts.hpp | 23 ++ .../algebra/storage/impl/vc_soa_getter.hpp | 31 ++ .../vc_soa/include/algebra/storage/vc_soa.hpp | 121 ++++++ core/include/detray/algebra/type_traits.hpp | 290 ++++++++++++++ .../algebra/utils/approximately_equal.hpp | 197 ++++++++++ core/include/detray/algebra/utils/casts.hpp | 110 ++++++ core/include/detray/algebra/utils/print.hpp | 97 +++++ core/include/detray/definitions/algebra.hpp | 13 +- .../detray/definitions/detail/assert.hpp | 15 + .../detray/definitions/detail/qualifiers.hpp | 18 + 101 files changed, 10172 insertions(+), 9 deletions(-) create mode 100644 core/include/detray/algebra/concepts.hpp create mode 100644 core/include/detray/algebra/frontend/CMakeLists.txt create mode 100644 core/include/detray/algebra/frontend/cmath/CMakeLists.txt create mode 100644 core/include/detray/algebra/frontend/cmath/include/algebra/cmath.hpp create mode 100644 core/include/detray/algebra/frontend/eigen/CMakeLists.txt create mode 100644 core/include/detray/algebra/frontend/eigen/include/algebra/eigen.hpp create mode 100644 core/include/detray/algebra/frontend/fastor/CMakeLists.txt create mode 100644 core/include/detray/algebra/frontend/fastor/include/algebra/fastor.hpp create mode 100644 core/include/detray/algebra/frontend/smatrix/CMakeLists.txt create mode 100644 core/include/detray/algebra/frontend/smatrix/include/algebra/smatrix.hpp create mode 100644 core/include/detray/algebra/frontend/vc_aos/CMakeLists.txt create mode 100644 core/include/detray/algebra/frontend/vc_aos/include/algebra/vc_aos.hpp create mode 100644 core/include/detray/algebra/frontend/vc_soa/CMakeLists.txt create mode 100644 core/include/detray/algebra/frontend/vc_soa/include/algebra/vc_soa.hpp create mode 100644 core/include/detray/algebra/math/CMakeLists.txt create mode 100644 core/include/detray/algebra/math/cmath/CMakeLists.txt create mode 100644 core/include/detray/algebra/math/cmath/include/algebra/math/cmath.hpp create mode 100644 core/include/detray/algebra/math/cmath/include/algebra/math/impl/cmath_matrix.hpp create mode 100644 core/include/detray/algebra/math/cmath/include/algebra/math/impl/cmath_operators.hpp create mode 100644 core/include/detray/algebra/math/cmath/include/algebra/math/impl/cmath_vector.hpp create mode 100644 core/include/detray/algebra/math/common/CMakeLists.txt create mode 100644 core/include/detray/algebra/math/common/include/algebra/math/boolean.hpp create mode 100644 core/include/detray/algebra/math/common/include/algebra/math/common.hpp create mode 100644 core/include/detray/algebra/math/eigen/CMakeLists.txt create mode 100644 core/include/detray/algebra/math/eigen/include/algebra/math/eigen.hpp create mode 100644 core/include/detray/algebra/math/eigen/include/algebra/math/impl/eigen_matrix.hpp create mode 100644 core/include/detray/algebra/math/eigen/include/algebra/math/impl/eigen_transform3.hpp create mode 100644 core/include/detray/algebra/math/eigen/include/algebra/math/impl/eigen_vector.hpp create mode 100644 core/include/detray/algebra/math/fastor/CMakeLists.txt create mode 100644 core/include/detray/algebra/math/fastor/include/algebra/math/fastor.hpp create mode 100644 core/include/detray/algebra/math/fastor/include/algebra/math/impl/fastor_matrix.hpp create mode 100644 core/include/detray/algebra/math/fastor/include/algebra/math/impl/fastor_transform3.hpp create mode 100644 core/include/detray/algebra/math/fastor/include/algebra/math/impl/fastor_vector.hpp create mode 100644 core/include/detray/algebra/math/generic/CMakeLists.txt create mode 100644 core/include/detray/algebra/math/generic/include/algebra/math/algorithms/matrix/decomposition/partial_pivot_lud.hpp create mode 100644 core/include/detray/algebra/math/generic/include/algebra/math/algorithms/matrix/determinant/cofactor.hpp create mode 100644 core/include/detray/algebra/math/generic/include/algebra/math/algorithms/matrix/determinant/hard_coded.hpp create mode 100644 core/include/detray/algebra/math/generic/include/algebra/math/algorithms/matrix/determinant/partial_pivot_lud.hpp create mode 100644 core/include/detray/algebra/math/generic/include/algebra/math/algorithms/matrix/inverse/cofactor.hpp create mode 100644 core/include/detray/algebra/math/generic/include/algebra/math/algorithms/matrix/inverse/hard_coded.hpp create mode 100644 core/include/detray/algebra/math/generic/include/algebra/math/algorithms/matrix/inverse/partial_pivot_lud.hpp create mode 100644 core/include/detray/algebra/math/generic/include/algebra/math/algorithms/utils/algorithm_finder.hpp create mode 100644 core/include/detray/algebra/math/generic/include/algebra/math/generic.hpp create mode 100644 core/include/detray/algebra/math/generic/include/algebra/math/impl/generic_matrix.hpp create mode 100644 core/include/detray/algebra/math/generic/include/algebra/math/impl/generic_transform3.hpp create mode 100644 core/include/detray/algebra/math/generic/include/algebra/math/impl/generic_vector.hpp create mode 100644 core/include/detray/algebra/math/smatrix/CMakeLists.txt create mode 100644 core/include/detray/algebra/math/smatrix/include/algebra/math/impl/smatrix_errorcheck.hpp create mode 100644 core/include/detray/algebra/math/smatrix/include/algebra/math/impl/smatrix_matrix.hpp create mode 100644 core/include/detray/algebra/math/smatrix/include/algebra/math/impl/smatrix_transform3.hpp create mode 100644 core/include/detray/algebra/math/smatrix/include/algebra/math/impl/smatrix_vector.hpp create mode 100644 core/include/detray/algebra/math/smatrix/include/algebra/math/smatrix.hpp create mode 100644 core/include/detray/algebra/math/vc_aos/CMakeLists.txt create mode 100644 core/include/detray/algebra/math/vc_aos/include/algebra/math/impl/vc_aos_matrix.hpp create mode 100644 core/include/detray/algebra/math/vc_aos/include/algebra/math/impl/vc_aos_transform3.hpp create mode 100644 core/include/detray/algebra/math/vc_aos/include/algebra/math/impl/vc_aos_vector.hpp create mode 100644 core/include/detray/algebra/math/vc_aos/include/algebra/math/vc_aos.hpp create mode 100644 core/include/detray/algebra/math/vc_soa/CMakeLists.txt create mode 100644 core/include/detray/algebra/math/vc_soa/include/algebra/math/impl/vc_soa_boolean.hpp create mode 100644 core/include/detray/algebra/math/vc_soa/include/algebra/math/impl/vc_soa_math.hpp create mode 100644 core/include/detray/algebra/math/vc_soa/include/algebra/math/impl/vc_soa_matrix.hpp create mode 100644 core/include/detray/algebra/math/vc_soa/include/algebra/math/impl/vc_soa_vector.hpp create mode 100644 core/include/detray/algebra/math/vc_soa/include/algebra/math/vc_soa.hpp create mode 100644 core/include/detray/algebra/storage/CMakeLists.txt create mode 100644 core/include/detray/algebra/storage/array/CMakeLists.txt create mode 100644 core/include/detray/algebra/storage/array/include/algebra/storage/array.hpp create mode 100644 core/include/detray/algebra/storage/cmath/CMakeLists.txt create mode 100644 core/include/detray/algebra/storage/cmath/include/algebra/storage/impl/cmath_getter.hpp create mode 100644 core/include/detray/algebra/storage/common/CMakeLists.txt create mode 100644 core/include/detray/algebra/storage/common/include/algebra/storage/array_operators.hpp create mode 100644 core/include/detray/algebra/storage/common/include/algebra/storage/matrix.hpp create mode 100644 core/include/detray/algebra/storage/common/include/algebra/storage/matrix_getter.hpp create mode 100644 core/include/detray/algebra/storage/common/include/algebra/storage/vector.hpp create mode 100644 core/include/detray/algebra/storage/eigen/CMakeLists.txt create mode 100644 core/include/detray/algebra/storage/eigen/include/algebra/storage/eigen.hpp create mode 100644 core/include/detray/algebra/storage/eigen/include/algebra/storage/impl/eigen_array.hpp create mode 100644 core/include/detray/algebra/storage/eigen/include/algebra/storage/impl/eigen_getter.hpp create mode 100644 core/include/detray/algebra/storage/fastor/CMakeLists.txt create mode 100644 core/include/detray/algebra/storage/fastor/include/algebra/storage/fastor.hpp create mode 100644 core/include/detray/algebra/storage/fastor/include/algebra/storage/impl/fastor_getter.hpp create mode 100644 core/include/detray/algebra/storage/fastor/include/algebra/storage/impl/fastor_matrix.hpp create mode 100644 core/include/detray/algebra/storage/smatrix/CMakeLists.txt create mode 100644 core/include/detray/algebra/storage/smatrix/include/algebra/storage/impl/smatrix_getter.hpp create mode 100644 core/include/detray/algebra/storage/smatrix/include/algebra/storage/smatrix.hpp create mode 100644 core/include/detray/algebra/storage/vc_aos/CMakeLists.txt create mode 100644 core/include/detray/algebra/storage/vc_aos/include/algebra/storage/impl/vc_aos_approximately_equal.hpp create mode 100644 core/include/detray/algebra/storage/vc_aos/include/algebra/storage/impl/vc_aos_concepts.hpp create mode 100644 core/include/detray/algebra/storage/vc_aos/include/algebra/storage/impl/vc_aos_getter.hpp create mode 100644 core/include/detray/algebra/storage/vc_aos/include/algebra/storage/vc_aos.hpp create mode 100644 core/include/detray/algebra/storage/vc_soa/CMakeLists.txt create mode 100644 core/include/detray/algebra/storage/vc_soa/include/algebra/storage/impl/vc_soa_casts.hpp create mode 100644 core/include/detray/algebra/storage/vc_soa/include/algebra/storage/impl/vc_soa_concepts.hpp create mode 100644 core/include/detray/algebra/storage/vc_soa/include/algebra/storage/impl/vc_soa_getter.hpp create mode 100644 core/include/detray/algebra/storage/vc_soa/include/algebra/storage/vc_soa.hpp create mode 100644 core/include/detray/algebra/type_traits.hpp create mode 100644 core/include/detray/algebra/utils/approximately_equal.hpp create mode 100644 core/include/detray/algebra/utils/casts.hpp create mode 100644 core/include/detray/algebra/utils/print.hpp create mode 100644 core/include/detray/definitions/detail/assert.hpp diff --git a/core/include/detray/algebra/concepts.hpp b/core/include/detray/algebra/concepts.hpp new file mode 100644 index 0000000000..edfb021fa3 --- /dev/null +++ b/core/include/detray/algebra/concepts.hpp @@ -0,0 +1,168 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s) +#include "detray/algebra/type_traits.hpp" + +// System include(s). +#include + +namespace detray::concepts { + +/// Arithmetic types +template +concept arithmetic = std::is_arithmetic_v; + +/// Arithmetic types +template +concept enumeration = std::is_enum_v; + +// Value concept: Single entry +template +concept value = detray::concepts::arithmetic>; + +// Element concept: Single entry, not necessarily for vector/matrix operations +template +concept element = detray::concepts::value || + detray::concepts::enumeration>; + +/// Scalar concept: Elements of vectors/matrices (can be simd vectors) +template +concept scalar = !algebra::traits::is_matrix && + !algebra::traits::is_vector && requires(T a, T b) { + { a + b } + ->std::convertible_to; + { a - b } + ->std::convertible_to; + { a* b } + ->std::convertible_to; + { a / b } + ->std::convertible_to; +}; + +/// Check if a scalar is simd +template +concept simd_scalar = scalar && !std::is_scalar_v; + +/// Index concept to access vector/matrix elements +template +concept index = std::is_integral_v && !std::same_as; + +/// Vector concepts +/// @{ +template +concept vector = algebra::traits::is_vector; + +template +concept vector2D = vector && (algebra::traits::size == 2); + +template +concept vector3D = vector && (algebra::traits::size == 3); +/// @} + +/// Point concepts +/// @{ +template +concept point = vector; + +template +concept point2D = point && (algebra::traits::size == 2); + +template +concept point3D = point && (algebra::traits::size == 3); +/// @} + +/// Matrix concepts +/// @{ +template +concept matrix = algebra::traits::is_matrix; + +template +concept square_matrix = matrix&& algebra::traits::is_square; + +template +concept row_matrix = matrix && (algebra::traits::rows == 1); + +template +concept row_matrix3D = row_matrix && (algebra::traits::rows == 3); + +template +concept column_matrix = matrix && (algebra::traits::columns == 1); + +template +concept column_matrix3D = column_matrix && (algebra::traits::rows == 3); + +template +concept matrix_compatible = matrix&& matrix&& std::convertible_to< + algebra::traits::index_t, algebra::traits::index_t>&& + std::convertible_to, + algebra::traits::index_t>; + +template +concept matrix_multipliable = + matrix_compatible && + (algebra::traits::columns == + algebra::traits::rows)&&requires(algebra::traits::scalar_t sa, + algebra::traits::scalar_t sb) { + {(sa * sb) + (sa * sb)}; +}; + +template +concept matrix_multipliable_into = + matrix_multipliable&& matrix_compatible&& + matrix_compatible && + (algebra::traits::rows == algebra::traits::rows)&&( + algebra::traits::columns == + algebra::traits::columns< + MB>)&&requires(algebra::traits::scalar_t sa, + algebra::traits::scalar_t sb, + algebra::traits::scalar_t& sc) { + {sc += (sa * sb)}; +}; +/// @} + +/// Transform concept +template +concept transform3D = requires(T trf) { + // Local type definitions + requires scalar; + requires vector3D; + requires point2D; + requires point3D; + + // Methods + trf.rotation(); + trf.translation(); + trf.point_to_global(typename T::vector3()); + trf.point_to_local(typename T::vector3()); + trf.vector_to_global(typename T::vector3()); + trf.vector_to_local(typename T::vector3()); +}; + +/// Algebra plugin concept +template +concept algebra = (concepts::value && + concepts::scalar && + concepts::index && + concepts::vector3D && + concepts::point2D && + concepts::point3D && + concepts::transform3D && + concepts::matrix>); + +/// Check if an algebra has soa layout +/// @{ +template +concept soa = (!concepts::arithmetic>); + +template +concept aos = (!concepts::soa); +/// @} + +} // namespace algebra::concepts diff --git a/core/include/detray/algebra/frontend/CMakeLists.txt b/core/include/detray/algebra/frontend/CMakeLists.txt new file mode 100644 index 0000000000..0740734c51 --- /dev/null +++ b/core/include/detray/algebra/frontend/CMakeLists.txt @@ -0,0 +1,32 @@ +# Algebra plugins library, part of the ACTS project (R&D line) +# +# (c) 2021-2024 CERN for the benefit of the ACTS project +# +# Mozilla Public License Version 2.0 + +# Set up all enabled libraries. +add_subdirectory( array_cmath ) + +if( ALGEBRA_PLUGINS_INCLUDE_EIGEN ) + add_subdirectory( eigen_generic ) + add_subdirectory( eigen_eigen ) +endif() + +if( ALGEBRA_PLUGINS_INCLUDE_SMATRIX ) + add_subdirectory( smatrix_generic ) + add_subdirectory( smatrix_smatrix ) +endif() + +if( ALGEBRA_PLUGINS_INCLUDE_VC ) + add_subdirectory( vc_aos ) + add_subdirectory( vc_aos_generic ) + add_subdirectory( vc_soa ) +endif() + +if( ALGEBRA_PLUGINS_INCLUDE_FASTOR ) + add_subdirectory( fastor_fastor ) +endif() + +if( ALGEBRA_PLUGINS_INCLUDE_VECMEM ) + add_subdirectory( vecmem_cmath ) +endif() diff --git a/core/include/detray/algebra/frontend/cmath/CMakeLists.txt b/core/include/detray/algebra/frontend/cmath/CMakeLists.txt new file mode 100644 index 0000000000..2ee813184a --- /dev/null +++ b/core/include/detray/algebra/frontend/cmath/CMakeLists.txt @@ -0,0 +1,13 @@ +# Algebra plugins library, part of the ACTS project (R&D line) +# +# (c) 2021-2023 CERN for the benefit of the ACTS project +# +# Mozilla Public License Version 2.0 + +# Set up the library. +algebra_add_library( algebra_array_cmath array_cmath + "include/algebra/array_cmath.hpp" ) +target_link_libraries( algebra_array_cmath + INTERFACE algebra::common algebra::array_storage algebra::cmath_math algebra::generic_math ) +algebra_test_public_headers( algebra_array_cmath + "algebra/array_cmath.hpp" ) diff --git a/core/include/detray/algebra/frontend/cmath/include/algebra/cmath.hpp b/core/include/detray/algebra/frontend/cmath/include/algebra/cmath.hpp new file mode 100644 index 0000000000..b11786a884 --- /dev/null +++ b/core/include/detray/algebra/frontend/cmath/include/algebra/cmath.hpp @@ -0,0 +1,153 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2020-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s). +#include "algebra/math/cmath.hpp" +#include "algebra/math/generic.hpp" +#include "algebra/math/impl/generic_matrix.hpp" +#include "algebra/storage/array.hpp" + +namespace algebra { + +/// @name Operators on @c algebra::array::storage_type +/// @{ + +using algebra::cmath::operator*; +using algebra::cmath::operator-; +using algebra::cmath::operator+; + +/// @} + +namespace getter { + +/// @name Getter functions on @c algebra::array::storage_type +/// @{ + +using cmath::storage::block; +using cmath::storage::element; +using cmath::storage::set_block; +using cmath::storage::vector; + +/// @} + +} // namespace getter + +namespace vector { + +/// @name Vector functions on @c algebra::array::storage_type +/// @{ + +// array specific implementations +using cmath::dot; +using cmath::normalize; + +// generic implementations +using cmath::cross; +using cmath::eta; +using cmath::norm; +using cmath::perp; +using cmath::phi; +using cmath::theta; + +/// @} + +} // namespace vector + +// Use special algorithms for 4 dimensional matrices +namespace generic { + +// Determinant algorithms +template +struct determinant_selector<4, array::matrix_type, + array::element_getter> { + using type = + matrix::determinant::hard_coded, + array::element_getter>; +}; + +// Inversion algorithms +template +struct inversion_selector<4, array::matrix_type, + array::element_getter> { + using type = matrix::inverse::hard_coded, + array::element_getter>; +}; + +} // namespace generic + +namespace matrix { + +/// @name Matrix functions on @c algebra::array::storage_type +/// @{ + +using cmath::identity; +using cmath::set_identity; +using cmath::set_zero; +using cmath::zero; + +// Uses generic implementation in the background +using cmath::determinant; +using cmath::inverse; +using cmath::transpose; + +using generic::math::set_inplace_product_left; +using generic::math::set_inplace_product_left_transpose; +using generic::math::set_inplace_product_right; +using generic::math::set_inplace_product_right_transpose; +using generic::math::set_product; +using generic::math::set_product_left_transpose; +using generic::math::set_product_right_transpose; +using generic::math::transposed_product; + +/// @} + +} // namespace matrix + +namespace array { + +/// @name cmath based transforms on @c algebra::array +/// @{ + +template +using transform3 = + generic::math::transform3; + +/// @} + +} // namespace array + +namespace plugin { + +/// Define the plugin types +/// @{ +template +struct array { + /// Define scalar type + using value_type = V; + + template + using simd = T; + + using boolean = bool; + using scalar = value_type; + using size_type = algebra::array::size_type; + using transform3D = algebra::array::transform3; + using point2D = algebra::array::point2; + using point3D = algebra::array::point3; + using vector3D = algebra::array::vector3; + + template + using matrix = algebra::array::matrix_type; +}; +/// @} + +} // namespace plugin + +} // namespace algebra diff --git a/core/include/detray/algebra/frontend/eigen/CMakeLists.txt b/core/include/detray/algebra/frontend/eigen/CMakeLists.txt new file mode 100644 index 0000000000..8e0d8ce965 --- /dev/null +++ b/core/include/detray/algebra/frontend/eigen/CMakeLists.txt @@ -0,0 +1,14 @@ +# Algebra plugins library, part of the ACTS project (R&D line) +# +# (c) 2021-2023 CERN for the benefit of the ACTS project +# +# Mozilla Public License Version 2.0 + +# Set up the library. +algebra_add_library( algebra_eigen_eigen eigen_eigen + "include/algebra/eigen_eigen.hpp" ) +target_link_libraries( algebra_eigen_eigen + INTERFACE algebra::common algebra::eigen_storage algebra::eigen_math algebra::generic_math + Eigen3::Eigen ) +algebra_test_public_headers( algebra_eigen_eigen + "algebra/eigen_eigen.hpp" ) diff --git a/core/include/detray/algebra/frontend/eigen/include/algebra/eigen.hpp b/core/include/detray/algebra/frontend/eigen/include/algebra/eigen.hpp new file mode 100644 index 0000000000..b671ff3871 --- /dev/null +++ b/core/include/detray/algebra/frontend/eigen/include/algebra/eigen.hpp @@ -0,0 +1,116 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2020-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s). +#include "algebra/math/eigen.hpp" +#include "algebra/math/generic.hpp" +#include "algebra/storage/eigen.hpp" + +// Eigen include(s). +#ifdef _MSC_VER +#pragma warning(push, 0) +#endif // MSVC +#include +#ifdef _MSC_VER +#pragma warning(pop) +#endif // MSVC + +namespace algebra { + +namespace getter { + +/// @name Getter functions on @c algebra::eigen +/// @{ + +using eigen::storage::block; +using eigen::storage::element; +using eigen::storage::set_block; +using eigen::storage::vector; + +/// @} + +} // namespace getter + +namespace vector { + +/// @name Vector functions on @c algebra::eigen::storage_type +/// @{ + +using eigen::math::cross; +using eigen::math::dot; +using eigen::math::eta; +using eigen::math::norm; +using eigen::math::normalize; +using eigen::math::perp; +using eigen::math::phi; +using eigen::math::theta; + +} // namespace vector + +namespace matrix { + +/// @name Matrix functions on @c algebra::eigen::storage_type +/// @{ + +using eigen::math::determinant; +using eigen::math::identity; +using eigen::math::inverse; +using eigen::math::set_identity; +using eigen::math::set_zero; +using eigen::math::transpose; +using eigen::math::zero; + +using generic::math::set_inplace_product_left; +using generic::math::set_inplace_product_left_transpose; +using generic::math::set_inplace_product_right; +using generic::math::set_inplace_product_right_transpose; +using generic::math::set_product; +using generic::math::set_product_left_transpose; +using generic::math::set_product_right_transpose; +using generic::math::transposed_product; + +/// @} + +} // namespace matrix + +namespace eigen { + +template +using transform3 = math::transform3; + +} // namespace eigen + +namespace plugin { + +/// Define the plugin types +/// @{ +template +struct eigen { + /// Define scalar type + using value_type = V; + + template + using simd = T; + + using boolean = bool; + using scalar = value_type; + using size_type = algebra::eigen::size_type; + using transform3D = algebra::eigen::transform3; + using point2D = algebra::eigen::point2; + using point3D = algebra::eigen::point3; + using vector3D = algebra::eigen::vector3; + + template + using matrix = algebra::eigen::matrix_type; +}; +/// @} + +} // namespace plugin + +} // namespace algebra diff --git a/core/include/detray/algebra/frontend/fastor/CMakeLists.txt b/core/include/detray/algebra/frontend/fastor/CMakeLists.txt new file mode 100644 index 0000000000..ffec83b1fe --- /dev/null +++ b/core/include/detray/algebra/frontend/fastor/CMakeLists.txt @@ -0,0 +1,13 @@ +# Algebra plugins library, part of the ACTS project (R&D line) +# +# (c) 2022-2023 CERN for the benefit of the ACTS project +# +# Mozilla Public License Version 2.0 + +# Set up the library. +algebra_add_library( algebra_fastor_fastor fastor_fastor + "include/algebra/fastor_fastor.hpp" ) +target_link_libraries( algebra_fastor_fastor + INTERFACE algebra::common algebra::fastor_storage algebra::fastor_math algebra::generic_math ) +algebra_test_public_headers( algebra_fastor_fastor + "algebra/fastor_fastor.hpp" ) diff --git a/core/include/detray/algebra/frontend/fastor/include/algebra/fastor.hpp b/core/include/detray/algebra/frontend/fastor/include/algebra/fastor.hpp new file mode 100644 index 0000000000..7038692a5c --- /dev/null +++ b/core/include/detray/algebra/frontend/fastor/include/algebra/fastor.hpp @@ -0,0 +1,123 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2022-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s). +#include "algebra/math/fastor.hpp" +#include "algebra/math/generic.hpp" +#include "algebra/storage/fastor.hpp" + +// Fastor include(s). +#ifdef _MSC_VER +#pragma warning(disable : 4244 4701 4702) +#endif // MSVC +#include +#ifdef _MSC_VER +#pragma warning(default : 4244 4701 4702) +#endif // MSVC + +namespace algebra { + +namespace getter { + +/// @name Getter functions on @c algebra::fastor::matrix_type +/// @{ + +using fastor::storage::block; +using fastor::storage::element; +using fastor::storage::set_block; +using fastor::storage::vector; + +/// @} + +} // namespace getter + +namespace vector { + +/// @name Vector functions on @c algebra::fastor::storage_type +/// @{ + +using fastor::math::cross; +using fastor::math::dot; +using fastor::math::eta; +using fastor::math::norm; +using fastor::math::normalize; +using fastor::math::perp; +using fastor::math::phi; +using fastor::math::theta; + +/// @} + +} // namespace vector + +namespace matrix { + +/// @name Matrix functions on @c algebra::fastor::storage_type +/// @{ + +using fastor::math::determinant; +using fastor::math::identity; +using fastor::math::inverse; +using fastor::math::set_identity; +using fastor::math::set_zero; +using fastor::math::transpose; +using fastor::math::zero; + +using generic::math::set_inplace_product_left; +using generic::math::set_inplace_product_left_transpose; +using generic::math::set_inplace_product_right; +using generic::math::set_inplace_product_right_transpose; +using generic::math::set_product; +using generic::math::set_product_left_transpose; +using generic::math::set_product_right_transpose; +using generic::math::transposed_product; + +/// @} + +} // namespace matrix + +namespace fastor { + +/// @name Transform on @c algebra::fastor::storage_type +/// @{ + +template +using transform3 = math::transform3; + +/// @} + +} // namespace fastor + +namespace plugin { + +/// Define the plugin types +/// @{ +template +struct fastor { + /// Define scalar type + using value_type = V; + + template + using simd = T; + + using boolean = bool; + using scalar = value_type; + using size_type = algebra::fastor::size_type; + using transform3D = algebra::fastor::transform3; + using point2D = algebra::fastor::point2; + using point3D = algebra::fastor::point3; + using vector3D = algebra::fastor::vector3; + + template + using matrix = algebra::fastor::matrix_type; +}; +/// @} + +} // namespace plugin + +} // namespace algebra diff --git a/core/include/detray/algebra/frontend/smatrix/CMakeLists.txt b/core/include/detray/algebra/frontend/smatrix/CMakeLists.txt new file mode 100644 index 0000000000..d9a061db01 --- /dev/null +++ b/core/include/detray/algebra/frontend/smatrix/CMakeLists.txt @@ -0,0 +1,13 @@ +# Algebra plugins library, part of the ACTS project (R&D line) +# +# (c) 2021-2023 CERN for the benefit of the ACTS project +# +# Mozilla Public License Version 2.0 + +# Set up the library. +algebra_add_library( algebra_smatrix_smatrix smatrix_smatrix + "include/algebra/smatrix_smatrix.hpp" ) +target_link_libraries( algebra_smatrix_smatrix + INTERFACE algebra::common algebra::smatrix_storage algebra::smatrix_math algebra::generic_math ) +algebra_test_public_headers( algebra_smatrix_smatrix + "algebra/smatrix_smatrix.hpp" ) diff --git a/core/include/detray/algebra/frontend/smatrix/include/algebra/smatrix.hpp b/core/include/detray/algebra/frontend/smatrix/include/algebra/smatrix.hpp new file mode 100644 index 0000000000..5575878485 --- /dev/null +++ b/core/include/detray/algebra/frontend/smatrix/include/algebra/smatrix.hpp @@ -0,0 +1,114 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2020-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s). +#include "algebra/math/generic.hpp" +#include "algebra/math/smatrix.hpp" +#include "algebra/storage/smatrix.hpp" + +namespace algebra { + +namespace getter { + +/// @name Getter functions on @c algebra::smatrix::matrix_type +/// @{ + +using smatrix::storage::block; +using smatrix::storage::element; +using smatrix::storage::set_block; +using smatrix::storage::vector; + +/// @} + +} // namespace getter + +namespace vector { + +/// @name Vector functions on @c algebra::smatrix::storage_type +/// @{ + +using smatrix::math::cross; +using smatrix::math::dot; +using smatrix::math::eta; +using smatrix::math::norm; +using smatrix::math::normalize; +using smatrix::math::perp; +using smatrix::math::phi; +using smatrix::math::theta; + +/// @} + +} // namespace vector + +namespace matrix { + +/// @name Matrix functions on @c algebra::smatrix::storage_type +/// @{ + +using smatrix::math::determinant; +using smatrix::math::identity; +using smatrix::math::inverse; +using smatrix::math::set_identity; +using smatrix::math::set_zero; +using smatrix::math::transpose; +using smatrix::math::zero; + +using generic::math::set_inplace_product_left; +using generic::math::set_inplace_product_left_transpose; +using generic::math::set_inplace_product_right; +using generic::math::set_inplace_product_right_transpose; +using generic::math::set_product; +using generic::math::set_product_left_transpose; +using generic::math::set_product_right_transpose; +using generic::math::transposed_product; + +/// @} + +} // namespace matrix + +namespace smatrix { + +/// @name SMatrix based transforms on @c algebra::smatrix::storage_type +/// @{ + +template +using transform3 = math::transform3; + +/// @} + +} // namespace smatrix + +namespace plugin { + +/// Define the plugin types +/// @{ +template +struct smatrix { + /// Define scalar type + using value_type = V; + + template + using simd = T; + + using boolean = bool; + using scalar = value_type; + using size_type = algebra::smatrix::size_type; + using transform3D = algebra::smatrix::transform3; + using point2D = algebra::smatrix::point2; + using point3D = algebra::smatrix::point3; + using vector3D = algebra::smatrix::vector3; + + template + using matrix = algebra::smatrix::matrix_type; +}; +/// @} + +} // namespace plugin + +} // namespace algebra diff --git a/core/include/detray/algebra/frontend/vc_aos/CMakeLists.txt b/core/include/detray/algebra/frontend/vc_aos/CMakeLists.txt new file mode 100644 index 0000000000..f5dd488929 --- /dev/null +++ b/core/include/detray/algebra/frontend/vc_aos/CMakeLists.txt @@ -0,0 +1,13 @@ +# Algebra plugins library, part of the ACTS project (R&D line) +# +# (c) 2021-2023 CERN for the benefit of the ACTS project +# +# Mozilla Public License Version 2.0 + +# Set up the library. +algebra_add_library( algebra_vc_aos vc_aos + "include/algebra/vc_aos.hpp" ) +target_link_libraries( algebra_vc_aos + INTERFACE algebra::common algebra::vc_aos_storage algebra::vc_aos_math algebra::generic_math ) +algebra_test_public_headers( algebra_vc_aos + "algebra/vc_aos.hpp" ) diff --git a/core/include/detray/algebra/frontend/vc_aos/include/algebra/vc_aos.hpp b/core/include/detray/algebra/frontend/vc_aos/include/algebra/vc_aos.hpp new file mode 100644 index 0000000000..a47601f946 --- /dev/null +++ b/core/include/detray/algebra/frontend/vc_aos/include/algebra/vc_aos.hpp @@ -0,0 +1,141 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2020-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s). +#include "algebra/math/generic.hpp" +#include "algebra/math/vc_aos.hpp" +#include "algebra/storage/vc_aos.hpp" + +// System include(s). +#include +#include + +namespace algebra { + +namespace getter { + +/// @name Getter functions on @c algebra::vc_aos::matrix_type +/// @{ + +using vc_aos::storage::block; +using vc_aos::storage::element; +using vc_aos::storage::set_block; +using vc_aos::storage::vector; + +/// @} + +} // namespace getter + +namespace vector { + +/// @name Vector functions on @c algebra::vc_aos types +/// @{ + +// Vc array specific +using vc_aos::math::cross; +using vc_aos::math::dot; +using vc_aos::math::eta; +using vc_aos::math::norm; +using vc_aos::math::normalize; +using vc_aos::math::perp; +using vc_aos::math::phi; +using vc_aos::math::theta; + +/// @} + +} // namespace vector + +// Use special algorithms for 4 dimensional matrices +namespace generic { + +// Determinant algorithms +template +struct determinant_selector<4, vc_aos::matrix_type, + vc_aos::element_getter> { + using type = + matrix::determinant::hard_coded, + vc_aos::element_getter>; +}; + +// Inversion algorithms +template +struct inversion_selector<4, vc_aos::matrix_type, + vc_aos::element_getter> { + using type = matrix::inverse::hard_coded, + vc_aos::element_getter>; +}; + +} // namespace generic + +namespace matrix { + +/// @name Matrix functions on @c algebra::vc_aos types +/// @{ + +using vc_aos::math::determinant; +using vc_aos::math::identity; +using vc_aos::math::inverse; +using vc_aos::math::set_identity; +using vc_aos::math::set_zero; +using vc_aos::math::transpose; +using vc_aos::math::zero; + +using generic::math::set_inplace_product_left; +using generic::math::set_inplace_product_left_transpose; +using generic::math::set_inplace_product_right; +using generic::math::set_inplace_product_right_transpose; +using generic::math::set_product; +using generic::math::set_product_left_transpose; +using generic::math::set_product_right_transpose; +using generic::math::transposed_product; + +/// @} + +} // namespace matrix + +namespace vc_aos { + +/// @name Vc based transforms on @c algebra::vc_aos::storage_type +/// @{ + +template +using transform3 = math::transform3; + +/// @} + +} // namespace vc_aos + +namespace plugin { + +/// Define the plugin types +/// @{ +template +struct vc_aos { + /// Define scalar type + using value_type = V; + + template + using simd = T; + + using boolean = bool; + using scalar = value_type; + using size_type = algebra::vc_aos::size_type; + using transform3D = algebra::vc_aos::transform3; + using point2D = algebra::vc_aos::point2; + using point3D = algebra::vc_aos::point3; + using vector3D = algebra::vc_aos::vector3; + + template + using matrix = algebra::vc_aos::matrix_type; +}; +/// @} + +} // namespace plugin + +} // namespace algebra diff --git a/core/include/detray/algebra/frontend/vc_soa/CMakeLists.txt b/core/include/detray/algebra/frontend/vc_soa/CMakeLists.txt new file mode 100644 index 0000000000..66432be3f0 --- /dev/null +++ b/core/include/detray/algebra/frontend/vc_soa/CMakeLists.txt @@ -0,0 +1,14 @@ +# Algebra plugins library, part of the ACTS project (R&D line) +# +# (c) 2023 CERN for the benefit of the ACTS project +# +# Mozilla Public License Version 2.0 + +# Set up the library. +algebra_add_library( algebra_vc_soa vc_soa + "include/algebra/vc_soa.hpp" ) +target_link_libraries( algebra_vc_soa + INTERFACE algebra::common algebra::vc_soa_storage algebra::vc_soa_math algebra::generic_math + algebra::vc_aos_math ) +algebra_test_public_headers( algebra_vc_soa + "algebra/vc_soa.hpp" ) diff --git a/core/include/detray/algebra/frontend/vc_soa/include/algebra/vc_soa.hpp b/core/include/detray/algebra/frontend/vc_soa/include/algebra/vc_soa.hpp new file mode 100644 index 0000000000..2612e71864 --- /dev/null +++ b/core/include/detray/algebra/frontend/vc_soa/include/algebra/vc_soa.hpp @@ -0,0 +1,131 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2023-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s). +#include "algebra/math/impl/generic_matrix.hpp" +#include "algebra/math/impl/vc_aos_transform3.hpp" +#include "algebra/math/vc_soa.hpp" +#include "algebra/storage/vc_soa.hpp" + +// System include(s). +#include +#include + +/// @name Operators on @c algebra::storage::vector types +/// @{ + +using algebra::storage::operator*; +using algebra::storage::operator/; +using algebra::storage::operator-; +using algebra::storage::operator+; + +/// @} + +namespace algebra { + +namespace getter { + +/// @name Getter functions on @c algebra::vc_soa types +/// @{ + +using vc_soa::storage::block; +using vc_soa::storage::element; +using vc_soa::storage::set_block; +using vc_soa::storage::vector; + +/// @} + +} // namespace getter + +namespace vector { + +/// @name Vector functions on @c algebra::vc_soa types +/// @{ + +using vc_soa::math::cross; +using vc_soa::math::dot; +using vc_soa::math::eta; +using vc_soa::math::norm; +using vc_soa::math::normalize; +using vc_soa::math::perp; +using vc_soa::math::phi; +using vc_soa::math::theta; + +/// @} + +} // namespace vector + +// Produces clash with matrix typedefs in other plugins +namespace matrix { + +using vc_soa::math::determinant; +using vc_soa::math::identity; +using vc_soa::math::inverse; +using vc_soa::math::set_identity; +using vc_soa::math::set_zero; +using vc_soa::math::transpose; +using vc_soa::math::zero; + +using generic::math::set_inplace_product_left; +using generic::math::set_inplace_product_left_transpose; +using generic::math::set_inplace_product_right; +using generic::math::set_inplace_product_right_transpose; +using generic::math::set_product; +using generic::math::set_product_left_transpose; +using generic::math::set_product_right_transpose; +using generic::math::transposed_product; + +} // namespace matrix + +namespace vc_soa { + +/// @name Vc based transforms on @c algebra::vc_soa types +/// @{ + +template +using transform3 = + algebra::vc_aos::math::transform3>; + +/// @} + +} // namespace vc_soa + +namespace plugin { + +/// Define the plugin types +/// @{ +template +struct vc_soa { + /// Define scalar precision + using value_type = V; + + template + using simd = Vc::Vector; + + using boolean = Vc::Mask; + + /// Linear Algebra type definitions + /// @{ + using scalar = simd; + using size_type = algebra::vc_soa::size_type; + using transform3D = algebra::vc_soa::transform3; + using point2D = algebra::vc_soa::point2; + using point3D = algebra::vc_soa::point3; + using vector3D = algebra::vc_soa::vector3; + + template + using matrix = algebra::vc_soa::matrix_type; + /// @} +}; +/// @} + +} // namespace plugin + +} // namespace algebra diff --git a/core/include/detray/algebra/math/CMakeLists.txt b/core/include/detray/algebra/math/CMakeLists.txt new file mode 100644 index 0000000000..3a3c9a84cd --- /dev/null +++ b/core/include/detray/algebra/math/CMakeLists.txt @@ -0,0 +1,23 @@ +# Algebra plugins library, part of the ACTS project (R&D line) +# +# (c) 2021-2024 CERN for the benefit of the ACTS project +# +# Mozilla Public License Version 2.0 + +# Set up all enabled libraries. +add_subdirectory( common ) +add_subdirectory( cmath ) +add_subdirectory( generic ) +if( ALGEBRA_PLUGINS_INCLUDE_EIGEN ) + add_subdirectory( eigen ) +endif() +if( ALGEBRA_PLUGINS_INCLUDE_FASTOR ) + add_subdirectory( fastor ) +endif() +if( ALGEBRA_PLUGINS_INCLUDE_SMATRIX ) + add_subdirectory( smatrix ) +endif() +if( ALGEBRA_PLUGINS_INCLUDE_VC ) + add_subdirectory( vc_aos ) + add_subdirectory( vc_soa ) +endif() diff --git a/core/include/detray/algebra/math/cmath/CMakeLists.txt b/core/include/detray/algebra/math/cmath/CMakeLists.txt new file mode 100644 index 0000000000..2bcc4057b1 --- /dev/null +++ b/core/include/detray/algebra/math/cmath/CMakeLists.txt @@ -0,0 +1,17 @@ +# Algebra plugins library, part of the ACTS project (R&D line) +# +# (c) 2021-2024 CERN for the benefit of the ACTS project +# +# Mozilla Public License Version 2.0 + +# Set up the library. +algebra_add_library(algebra_cmath_math cmath_math + # impl include + "include/algebra/math/cmath.hpp" + "include/algebra/math/impl/cmath_matrix.hpp" + "include/algebra/math/impl/cmath_operators.hpp" + "include/algebra/math/impl/cmath_vector.hpp") +target_link_libraries(algebra_cmath_math + INTERFACE algebra::common algebra::common_math algebra::generic_math) +algebra_test_public_headers( algebra_cmath_math + "algebra/math/cmath.hpp" ) diff --git a/core/include/detray/algebra/math/cmath/include/algebra/math/cmath.hpp b/core/include/detray/algebra/math/cmath/include/algebra/math/cmath.hpp new file mode 100644 index 0000000000..5423775d38 --- /dev/null +++ b/core/include/detray/algebra/math/cmath/include/algebra/math/cmath.hpp @@ -0,0 +1,15 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2020-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Impl include(s). +#include "algebra/math/boolean.hpp" +#include "algebra/math/common.hpp" +#include "algebra/math/impl/cmath_matrix.hpp" +#include "algebra/math/impl/cmath_operators.hpp" +#include "algebra/math/impl/cmath_vector.hpp" diff --git a/core/include/detray/algebra/math/cmath/include/algebra/math/impl/cmath_matrix.hpp b/core/include/detray/algebra/math/cmath/include/algebra/math/impl/cmath_matrix.hpp new file mode 100644 index 0000000000..53e135d7ce --- /dev/null +++ b/core/include/detray/algebra/math/cmath/include/algebra/math/impl/cmath_matrix.hpp @@ -0,0 +1,86 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2022-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s). +#include "algebra/concepts.hpp" +#include "algebra/math/common.hpp" +#include "algebra/math/generic.hpp" +#include "algebra/qualifiers.hpp" + +namespace algebra::cmath { + +/// @returns zero matrix of type @tparam matrix_t +template +requires(std::is_scalar_v) + ALGEBRA_HOST_DEVICE constexpr matrix_t zero() { + matrix_t ret; + + for (std::size_t j = 0; j < algebra::traits::columns; ++j) { + for (std::size_t i = 0; i < algebra::traits::rows; ++i) { + ret[j][i] = 0; + } + } + + return ret; +} + +/// @returns identity matrix of type @tparam matrix_t +template +requires(std::is_scalar_v) + ALGEBRA_HOST_DEVICE constexpr auto identity() { + auto ret{zero()}; + + for (std::size_t i = 0; i < algebra::traits::rank; ++i) { + ret[i][i] = 1; + } + + return ret; +} + +/// Set @param m as zero matrix +template class array_t> +ALGEBRA_HOST_DEVICE constexpr void set_zero( + array_t, COLS> &m) { + m = zero, COLS>>(); +} + +/// Set @param m as identity matrix +template class array_t> +ALGEBRA_HOST_DEVICE constexpr void set_identity( + array_t, COLS> &m) { + m = identity, COLS>>(); +} + +/// @returns the transpose matrix of @param m +template class array_t> +ALGEBRA_HOST_DEVICE constexpr auto transpose( + const array_t, COLS> &m) { + return algebra::generic::math::transpose(m); +} + +/// @returns the determinant of @param m +template class array_t> +ALGEBRA_HOST_DEVICE constexpr scalar_t determinant( + const array_t, COLS> &m) { + return algebra::generic::math::determinant(m); +} + +/// @returns the determinant of @param m +template class array_t> +ALGEBRA_HOST_DEVICE constexpr auto inverse( + const array_t, COLS> &m) { + return algebra::generic::math::inverse(m); +} + +} // namespace algebra::cmath diff --git a/core/include/detray/algebra/math/cmath/include/algebra/math/impl/cmath_operators.hpp b/core/include/detray/algebra/math/cmath/include/algebra/math/impl/cmath_operators.hpp new file mode 100644 index 0000000000..6bc926b658 --- /dev/null +++ b/core/include/detray/algebra/math/cmath/include/algebra/math/impl/cmath_operators.hpp @@ -0,0 +1,215 @@ +/** Algebra plugins library, part of the ACTS project + * + * (c) 2020-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s). +#include "algebra/qualifiers.hpp" + +// System include(s). +#include +#include + +namespace algebra::cmath { + +/// @name Operators on 2-element arrays +/// @{ + +template