From 4f551bae785c546eef6b2dc22ca4281d17ea3d55 Mon Sep 17 00:00:00 2001 From: Christian Trott Date: Wed, 4 Sep 2024 12:54:53 -0600 Subject: [PATCH] Don't use get for std::complex slice specifier and test that complex works like pair as slice specifier *barf* --- .../experimental/__p2630_bits/submdspan_extents.hpp | 12 ++++++++++++ tests/test_submdspan.cpp | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/experimental/__p2630_bits/submdspan_extents.hpp b/include/experimental/__p2630_bits/submdspan_extents.hpp index 1ee8007f..67d7fa7a 100644 --- a/include/experimental/__p2630_bits/submdspan_extents.hpp +++ b/include/experimental/__p2630_bits/submdspan_extents.hpp @@ -105,6 +105,12 @@ constexpr auto first_of(const Slice &i) { return std::get<0>(i); } +template +MDSPAN_INLINE_FUNCTION +constexpr auto first_of(const std::complex &i) { + return i.real(); +} + template MDSPAN_INLINE_FUNCTION constexpr OffsetType @@ -136,6 +142,12 @@ constexpr auto last_of(std::integral_constant, const Extents &, return std::get<1>(i); } +template +MDSPAN_INLINE_FUNCTION +constexpr auto last_of(std::integral_constant, const Extents &, const std::complex &i) { + return i.imag(); +} + // Suppress spurious warning with NVCC about no return statement. // This is a known issue in NVCC and NVC++ // Depending on the CUDA and GCC version we need both the builtin diff --git a/tests/test_submdspan.cpp b/tests/test_submdspan.cpp index a0f4e043..184326d8 100644 --- a/tests/test_submdspan.cpp +++ b/tests/test_submdspan.cpp @@ -140,6 +140,7 @@ using submdspan_test_types = // layout_right to layout_right Check Extents Preservation , std::tuple, args_t<10>, Kokkos::extents, Kokkos::full_extent_t> , std::tuple, args_t<10>, Kokkos::extents, std::pair> + , std::tuple, args_t<10>, Kokkos::extents, std::complex> , std::tuple, args_t<10>, Kokkos::extents, int> , std::tuple, args_t<10,20>, Kokkos::extents, Kokkos::full_extent_t, Kokkos::full_extent_t> , std::tuple, args_t<10,20>, Kokkos::extents, std::pair, Kokkos::full_extent_t> @@ -274,6 +275,10 @@ struct TestSubMDSpan< return std::pair(1,3); } MDSPAN_INLINE_FUNCTION + static auto create_slice_arg(std::complex) { + return std::complex{1.,3.}; + } + MDSPAN_INLINE_FUNCTION static auto create_slice_arg(Kokkos::strided_slice) { return Kokkos::strided_slice{1,3,2}; } @@ -300,6 +305,12 @@ struct TestSubMDSpan< } template MDSPAN_INLINE_FUNCTION + static bool check_submdspan_match(int src_idx, int sub_idx, SrcMDSpan src_mds, SubMDSpan sub_mds, std::index_sequence, std::index_sequence, std::complex p, SliceArgs ... slices) { + using idx_t = typename SubMDSpan::index_type; + return (sub_mds.extent(sub_idx)==static_cast(p.imag()-p.real())) && check_submdspan_match(++src_idx, ++sub_idx, src_mds, sub_mds, std::index_sequence(), std::index_sequence(), slices...); + } + template + MDSPAN_INLINE_FUNCTION static bool check_submdspan_match(int src_idx, int sub_idx, SrcMDSpan src_mds, SubMDSpan sub_mds, std::index_sequence, std::index_sequence, Kokkos::strided_slice p, SliceArgs ... slices) { using idx_t = typename SubMDSpan::index_type;