From 3d4032481486a5424338784f720e7dc33fbdbe01 Mon Sep 17 00:00:00 2001 From: Christian Trott Date: Sun, 8 Jan 2023 20:00:34 -0700 Subject: [PATCH] Support and add test for compile time zero length/stride index range --- .../__p2630_bits/submdspan_extents.hpp | 4 +++- tests/test_submdspan.cpp | 21 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/include/experimental/__p2630_bits/submdspan_extents.hpp b/include/experimental/__p2630_bits/submdspan_extents.hpp index 5d6d8fba..f234b4e9 100644 --- a/include/experimental/__p2630_bits/submdspan_extents.hpp +++ b/include/experimental/__p2630_bits/submdspan_extents.hpp @@ -173,7 +173,9 @@ template MDSPAN_INLINE_FUNCTION constexpr auto divide(const integral_constant &, const integral_constant &) { - return integral_constant(); + // cutting short division by zero + // this is used for strided_index_range with zero extent/stride + return integral_constant(); } // multiply which can deal with integral constant preservation diff --git a/tests/test_submdspan.cpp b/tests/test_submdspan.cpp index b2d9c35b..92f58926 100644 --- a/tests/test_submdspan.cpp +++ b/tests/test_submdspan.cpp @@ -157,6 +157,7 @@ using submdspan_test_types = , std::tuple, args_t<6,4,5,6,7,8>, stdex::extents, int, stdex::full_extent_t, std::pair, int, stdex::full_extent_t, int> // layout_right to layout_stride , std::tuple, args_t<10>, stdex::dextents, stdex::strided_index_range> + , std::tuple, args_t<10>, stdex::extents, stdex::strided_index_range,std::integral_constant>> , std::tuple, args_t<10,20>, stdex::dextents, stdex::strided_index_range, int> , std::tuple, args_t<10,20>, stdex::dextents, stdex::full_extent_t, std::pair> , std::tuple, args_t<10,20>, stdex::dextents, std::pair, stdex::strided_index_range> @@ -199,15 +200,20 @@ struct TestSubMDSpan< return 2; } MDSPAN_INLINE_FUNCTION - static std::pair create_slice_arg(std::pair) { + static auto create_slice_arg(std::pair) { return std::pair(1,3); } MDSPAN_INLINE_FUNCTION - static stdex::strided_index_range create_slice_arg(stdex::strided_index_range) { + static auto create_slice_arg(stdex::strided_index_range) { return stdex::strided_index_range{1,3,2}; } + template MDSPAN_INLINE_FUNCTION - static stdex::full_extent_t create_slice_arg(stdex::full_extent_t) { + static auto create_slice_arg(stdex::strided_index_range, std::integral_constant>) { + return stdex::strided_index_range, std::integral_constant>{1}; + } + MDSPAN_INLINE_FUNCTION + static auto create_slice_arg(stdex::full_extent_t) { return stdex::full_extent; } @@ -223,11 +229,18 @@ struct TestSubMDSpan< } template MDSPAN_INLINE_FUNCTION - static bool match_expected_extents(int src_idx, int sub_idx, SrcExtents src_ext, SubExtents sub_ext, stdex::strided_index_range p, SliceArgs ... slices) { + static bool match_expected_extents(int src_idx, int sub_idx, SrcExtents src_ext, SubExtents sub_ext, + stdex::strided_index_range p, SliceArgs ... slices) { return (sub_ext.extent(sub_idx)==(p.extent+p.stride-1)/p.stride) && match_expected_extents(++src_idx, ++sub_idx, src_ext, sub_ext, slices...); } template MDSPAN_INLINE_FUNCTION + static bool match_expected_extents(int src_idx, int sub_idx, SrcExtents src_ext, SubExtents sub_ext, + stdex::strided_index_range,std::integral_constant> p, SliceArgs ... slices) { + return (sub_ext.extent(sub_idx)==0) && match_expected_extents(++src_idx, ++sub_idx, src_ext, sub_ext, slices...); + } + template + MDSPAN_INLINE_FUNCTION static bool match_expected_extents(int src_idx, int sub_idx, SrcExtents src_ext, SubExtents sub_ext, stdex::full_extent_t, SliceArgs ... slices) { return (sub_ext.extent(sub_idx)==src_ext.extent(src_idx)) && match_expected_extents(++src_idx, ++sub_idx, src_ext, sub_ext, slices...); }