Fix DivideError in affine_transform for degenerate rational inputs#47
Open
Fix DivideError in affine_transform for degenerate rational inputs#47
Conversation
When the affine transformation has no valid integer mappings (e.g. when the denominator s is even and b_int has odd components while all entries of A_int are even), the carry set becomes empty, producing zero-sized tensors that cause a DivideError during reshape. Handle this by detecting empty carry sets after both the main loop and the open boundary extension loop, returning zero tensors with a warning. Fixes #46 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
DivideErrorRoot Cause
When the common denominator
sis even andb_inthas odd components while all entries ofA_intare even, the constraintA*x + b + c ≡ 0 (mod 2)is never satisfied. This causesaffine_transform_coreto return an empty carry set, producing tensors with zero-sized dimensions. Subsequentreshape(tensor, 0, :)hits0 ÷ 0→DivideError.The transformation is mathematically degenerate — it maps no integer grid points to integer grid points. A warning is emitted to alert users.
Fixes #46
Test plan
degenerate_rational (issue #46)that reproduces the exact crash🤖 Generated with Claude Code