Repository navigation
Add range_slice - #479
Add range_slice#479
range_slice#479Conversation
…g for range_slice; add tests for range_slice
…lice_* to Rank*_extent_slice_*
…e of size_t literal in submdspan_extents
mhoemmen
left a comment
There was a problem hiding this comment.
Should calculate_extents::value always return IndexType or cw of IndexType, instead of deducing the return type?
crtrott
left a comment
There was a problem hiding this comment.
Besides one place where I think we use the previous code, we also should name canonical_range_slice to canonical-slice-range to make it clearer that that thing doesn't return a range_slice. Note that the C++ draft has a typo where it uses both spellings ....
| return canonical_range_slice<IndexType>( | ||
| c_first, | ||
| subtract_ice<IndexType>(c_first, c_last) | ||
| ); |
There was a problem hiding this comment.
This seems excessive, the previous code was perfectly fine or? I mean this thing does return extent_slice in the end doesn't it?
There was a problem hiding this comment.
The wording is not always the best way to implement something. We are making sometimes reuse decisions etc. to make the wording easier, more consistent, easier to understand. That doesn't mean one should implement it that way. So in this case I really don't see a reason why we would not use the previous code?
There was a problem hiding this comment.
I rewrote this part because I found it easier to understand and less lines of code.
I.e. the pair case is just the range_slice with a stride of 1
I can always revert it if you would like, in the end it works out to the same thing
There was a problem hiding this comment.
I think I'd rather have it reverted. It makes more sense to me to directly return the extent_slice.
| // Some compilers do not do ctad properly with canonical_range_slice | ||
| template<class OffsetType, class ExtentType, class StrideType> | ||
| constexpr auto make_extent_slice(OffsetType offset, ExtentType extent, StrideType stride) | ||
| { | ||
| return extent_slice<OffsetType, ExtentType, StrideType>{offset, extent, stride}; | ||
| } |
There was a problem hiding this comment.
Just an optional suggestion -- sometimes return type deduction can slow down builds.
| // Some compilers do not do ctad properly with canonical_range_slice | |
| template<class OffsetType, class ExtentType, class StrideType> | |
| constexpr auto make_extent_slice(OffsetType offset, ExtentType extent, StrideType stride) | |
| { | |
| return extent_slice<OffsetType, ExtentType, StrideType>{offset, extent, stride}; | |
| } | |
| // Some compilers do not do ctad properly with canonical_range_slice | |
| template<class OffsetType, class ExtentType, class StrideType> | |
| constexpr extent_slice<OffsetType, ExtentType, StrideType> | |
| make_extent_slice(OffsetType offset, ExtentType extent, StrideType stride) | |
| { | |
| return {offset, extent, stride}; | |
| } |
There was a problem hiding this comment.
🟡 Changes recommended
Static reversed ranges can produce incorrect extents, and range_slice does not enforce required index-like component types.
3 open findings
What changed in this PR
Adds C++26 range_slice support alongside extent_slice throughout submdspan processing.
Changes:
- Introduces and canonicalizes
range_slice. - Updates mapping and extent deduction.
- Expands slice and submdspan tests.
| File | Description |
|---|---|
include/experimental/__p2630_bits/strided_slice.hpp |
Defines range_slice. |
include/experimental/__p2630_bits/submdspan_canonicalize_slices.hpp |
Canonicalizes ranges into extent slices. |
include/experimental/__p2630_bits/submdspan_extents.hpp |
Canonicalizes slices during extent deduction. |
include/experimental/__p2630_bits/submdspan_mapping.hpp |
Recognizes contiguous range slices. |
tests/test_strided_slice.cpp |
Tests slice construction and members. |
tests/test_canonicalize_slices.cpp |
Tests dynamic and static canonicalization. |
tests/test_submdspan.cpp |
Exercises ranges across layouts. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
mdspan PRs included: - fixup project name [#474](kokkos/mdspan#474) - run pre-commit [#475](kokkos/mdspan#475) - strided_slice [#476](kokkos/mdspan#476) - codeql underflow issue [#477](kokkos/mdspan#477) - license fixup [#478](kokkos/mdspan#478) - range-slice [#479](kokkos/mdspan#479) Signed-off-by: Christian Trott <crtrott@sandia.gov>



Fixes #472