fix(arange): guard si32 path on all operands being integer-typed#27
Merged
gokulkrishna98 merged 1 commit intoJun 29, 2026
Merged
Conversation
Checking only start.type.element_type was insufficient: mixed-type calls like arange(0, 5, 0.5) have int start/end but float step, so the old guard would select si32 and truncate step (0.5 → 0), producing a degenerate range. Now all three operands must be integer-typed for the static-shape si32 path; any float operand falls back to target_type. Adds test_mixed_int_float_operands to cover this case.
b7da02f to
efcc690
Compare
DawerG
approved these changes
Jun 29, 2026
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.
Problem
torch.arangeaccepts mixed int/float scalar bounds — e.g.arange(0, 5, 0.5)wherestart/endareintbutstepisfloat. The previous fix gated thesi32optimisation onstart.type.element_typealone, sostep(arriving asf32) would be cast tosi32, truncating0.5 → 0and producing a degenerate range.Fix
Check all three operands before selecting the integer path:
If any operand is float, fall back to
target_type(float) for therange_call, preserving the original behaviour for float-step aranges.Tests
TestArange::test_mixed_int_float_operands:arange(0, 5, 0.5, dtype=float32)must produce the correct 10-element output and not truncate the float step.