Repository navigation
Fix generic Array API rounding exponents - #69
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the Array API exponent-convention fix.
No open issues 🎉
What changed in this PR
Corrects the generic Array API _frexp fallback so rounding uses the expected exponent convention, fixing unrepresentable results such as rounding 2.5 to E2M1.
Changes:
- Adjusts exponent estimates near powers of two while keeping comparisons finite and preserving subnormal values.
- Adds scalar, NumPy, and strict Array API parity tests across formats, rounding modes, saturation settings, and float32/float64 inputs.
- Covers exponent boundaries, signed zero, strided and duplicate values, and empty arrays.
| File | Description |
|---|---|
test/test_array_api.py |
Adds exponent boundary checks and rounding regression tests. |
src/gfloat/round_ndarray.py |
Corrects fallback exponents and handles estimates just below powers of two. |
Review effort: Balanced
Collaborator
|
Thanks @yashb98 — nice spot, great tests. I've pushed a small follow-up commit that keeps your logic and results identical but rewrites the comment and comparison slightly. |
awf
marked this pull request as ready for review
November 7, 2026 16:40
Contributor
Author
|
Thanks for reviewing this and clarifying the comments. I've kept your rewrite and switched |
Collaborator
|
Thanks! |
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.
Rounding 2.5 to E2M1 with array-api-strict currently returns 2.5, which the format cannot represent; scalar and NumPy rounding return 2.0. The generic
_frexpfallback returns a base-2 order instead of the exponent expected by its caller. I propose correcting the exponent convention and checking estimates immediately below powers of two, while keeping the comparison finite at the largest input and preserving subnormal values.The regression tests compare scalar, NumPy and strict results across float32/float64, all rounding modes, both saturation settings and three formats, with signed-zero, strided, duplicate and empty inputs. Separate exponent checks cover adjacent powers and finite extremes.
Testing:
The 32-bit runs used local PRoot/QEMU and unchanged ml_dtypes cross-built with GCC 14.2 and the guest headers; ARM32 pyzmq used Debian ZeroMQ.