Repository navigation
Conversation
`partition` picks the slice fast path when the first lane is contiguous, then calls `as_slice_mut().unwrap()` on each lane. A lane along an inverted axis (e.g. after `invert_axis` or `s![..;-1]`) is contiguous but has stride -1, so `as_slice_mut()` returns `None` and the unwrap panics. Check `as_slice_mut().is_some()` instead, so such lanes go through the copying path that already handles arbitrary strides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
partitionpanics when the lanes alongaxishave a negative stride:partitioncopies the array withto_owned(), which keeps the negative stride, and then takes the slice fast path if the first laneis_contiguous(). A lane with stride -1 counts as contiguous, butas_slice_mut()only returns a slice for standard layout, so theunwrap()in the fast path fails.This checks
as_slice_mut().is_some()instead, which is exactly what the fast path needs. Lanes with a negative stride now go through the existing copy path, which already handles any stride.Added
test_partition_negative_stridecovering an inverted axis and a reversed view; it panics without the change.cargo test -p ndarray -F approx,serde,rayon,cargo clippy -F approx,serde,rayonandcargo +nightly fmt --all --checkpass locally.I used Claude Code to write this change.