diff --git a/core/include/detray/algebra/concepts.hpp b/core/include/detray/algebra/concepts.hpp new file mode 100644 index 000000000..edfb021fa --- /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 000000000..0740734c5 --- /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 000000000..2ee813184 --- /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 000000000..b11786a88 --- /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 000000000..8e0d8ce96 --- /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 000000000..b671ff387 --- /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 000000000..ffec83b1f --- /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 000000000..7038692a5 --- /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 000000000..d9a061db0 --- /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 000000000..557587848 --- /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 000000000..f5dd48892 --- /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 000000000..a47601f94 --- /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 000000000..66432be3f --- /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 000000000..2612e7186 --- /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 000000000..3a3c9a84c --- /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 000000000..2bcc4057b --- /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 000000000..5423775d3 --- /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 000000000..53e135d7c --- /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 000000000..6bc926b65 --- /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