Open
Conversation
Note that the "slice" class does not support subclassing hence we had to add NormalizedSlice to ConvertibleToIndexExpr.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends pytato’s indexing interface to accept NormalizedSlice objects directly (in addition to built-in slice), addressing #633 and enabling NormalizedSlice to be used as a user-facing indexer.
Changes:
- Allow
NormalizedSliceto be passed intoArray.__getitem__by wideningConvertibleToIndexExpr. - Update
_index_into/_normalize_sliceto accept and normalizeNormalizedSlicein addition toslice. - Add a regression test ensuring
NormalizedSlicecan be used as an indexer and update the pyright baseline.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
pytato/array.py |
Extends index typing to include NormalizedSlice as a valid input index expression. |
pytato/utils.py |
Accepts NormalizedSlice in indexing validation/normalization and updates slice normalization logic. |
test/test_pytato.py |
Adds a test covering NormalizedSlice being usable as an indexer. |
.basedpyright/baseline.json |
Removes resolved/changed type-check baseline entries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+473
to
+478
| if _is_non_negative(stop + axis_len) and not _is_non_positive(axis_len - stop): | ||
| stop = stop % axis_len | ||
| elif _is_non_negative(stop - axis_len): | ||
| stop = axis_len if step > 0 else axis_len - 1 | ||
| else: | ||
| raise NotImplementedError | ||
| stop = 0 if step > 0 else -1 |
| assert 3*x == new_expr | ||
|
|
||
|
|
||
| def test_normalized_slice_is_valid_indexee(): |
Comment on lines
+2069
to
+2072
| a = pt.make_placeholder("a", 10) | ||
| assert a[NormalizedSlice(0, 10, 1)] == a[:] | ||
|
|
||
|
|
Comment on lines
+461
to
+468
| if _is_non_negative(start + axis_len) and not _is_non_positive( | ||
| axis_len - start | ||
| ): | ||
| start = start % axis_len | ||
| elif _is_non_negative(start - axis_len): | ||
| start = axis_len if step > 0 else axis_len - 1 | ||
| else: | ||
| raise NotImplementedError | ||
| start = 0 if step > 0 else -1 |
Owner
|
These sound like reasonable comments for the most part. @kaushikcfd, could you take a look? |
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.
Note:
"Fix this issue <https://github.com/inducer/pytato/issues/633>". I only fixed the types in the body ofnormalize_slice_len, which I figured was easier than telling Claude about the_is_non_(negative|positive).Closes #633.