Skip to content

Add range_slice - #479

Merged
crtrott merged 12 commits into
kokkos:stablefrom
nmm0:add-range-slice
Oct 14, 2026
Merged

crtrott merged 12 commits into
kokkos:stablefrom
nmm0:add-range-slice

Conversation

@nmm0

@nmm0 nmm0 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #472

@nmm0 nmm0 changed the title Add range slice Add range_slice Oct 12, 2026
Comment thread include/experimental/__p2630_bits/submdspan_canonicalize_slices.hpp Outdated

@mhoemmen mhoemmen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should calculate_extents::value always return IndexType or cw of IndexType, instead of deducing the return type?

@nmm0
nmm0 requested a review from mhoemmen October 13, 2026 21:22

@crtrott crtrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ....

Comment on lines +431 to +434
return canonical_range_slice<IndexType>(
c_first,
subtract_ice<IndexType>(c_first, c_last)
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems excessive, the previous code was perfectly fine or? I mean this thing does return extent_slice in the end doesn't it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd rather have it reverted. It makes more sense to me to directly return the extent_slice.

Comment on lines +358 to +363
// 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};
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an optional suggestion -- sometimes return type deduction can slow down builds.

Suggested change
// 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};
}

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment thread include/experimental/__p2630_bits/submdspan_canonicalize_slices.hpp
Comment thread include/experimental/__p2630_bits/strided_slice.hpp
Comment thread tests/test_canonicalize_slices.cpp Outdated
@crtrott
crtrott merged commit fb4f421 into kokkos:stable Oct 14, 2026
16 checks passed
dalg24 pushed a commit to kokkos/kokkos that referenced this pull request Oct 15, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split strided_slice into extent_slice and range_slice

4 participants