Bugfix: Fix slice to support empty range - #161
Merged
Merged
Conversation
benikm91
force-pushed
the
slice-for-empty-range
branch
from
August 25, 2026 13:23
64b74f7 to
1aa924e
Compare
benikm91
force-pushed
the
slice-for-empty-range
branch
from
August 25, 2026 13:26
1aa924e to
de633c4
Compare
marcelluethi
approved these changes
Aug 26, 2026
marcelluethi
left a comment
Contributor
There was a problem hiding this comment.
Allowing empty ranges makes a lot of sense. The implementation and tests look good to me.
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.
throws an error, despite having a potential use, e.g., autoregressive prediction starting with an empty sequence that has a tensor structure
Tensor2[Sequence, Embedding, Float32], but theSequencedimension has extent 0 initially.This failed because the translation from Scala Range to Python Range used
range.headandrange.lastinstead ofstartandendvalues.headandlastfail on an empty range. This PR fixes this mistake by usingstartandend, while respecting that Scala Ranges can be inclusive.Additionally, it fixes a bug where
(7 to 0 by -1)did not work, as the end would be-1in Python (exclusive range), but it must be encoded withNonein Python.Additionally, it adds a
requirestatement that checks whether the passed range makes sense, failing fast with a clear error message.