Skip to content

Fix DivideError in affine_transform for degenerate rational inputs#47

Open
shinaoka wants to merge 1 commit intomainfrom
fix/affine-degenerate-rational
Open

Fix DivideError in affine_transform for degenerate rational inputs#47
shinaoka wants to merge 1 commit intomainfrom
fix/affine-degenerate-rational

Conversation

@shinaoka
Copy link
Copy Markdown
Member

Summary

  • Handle the case where an affine transformation has no valid integer mappings (empty carry set) by returning zero tensors with a warning instead of crashing with DivideError
  • Add protection in both the main carry loop and the open boundary extension loop
  • Add regression test for the exact input from the issue

Root Cause

When the common denominator s is even and b_int has odd components while all entries of A_int are even, the constraint A*x + b + c ≡ 0 (mod 2) is never satisfied. This causes affine_transform_core to return an empty carry set, producing tensors with zero-sized dimensions. Subsequent reshape(tensor, 0, :) hits 0 ÷ 0DivideError.

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

  • Added regression test degenerate_rational (issue #46) that reproduces the exact crash
  • All existing affine tests still pass (1731 pass, 0 error)

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DivideError in affine_transform_mpo

1 participant