Fix binary64 ndarray encoding overflow for signed zero - #64
Merged
Merged
Conversation
awf
marked this pull request as draft
September 18, 2026 15:02
|
There was probably no doubt in your mind, but I can confirm that this does fix my tests. |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The fix directly addresses the reported overflow and has focused coverage for all described cases.
Review effort: Lite
Findings: None
What changed in this PR
Fixes binary64 ndarray encoding overflow for signed zero by using uint64 zero code points and adding regression tests.
Changes:
- Cast zero code points to
np.uint64beforenp.where. - Add coverage for signed zeros, multidimensional, nonzero, and empty arrays.
| File | Description |
|---|---|
src/gfloat/encode_ndarray.py |
Prevents signed-zero code conversion overflow. |
test/test_encode.py |
Adds regression tests for affected inputs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Collaborator
Author
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.
encode_ndarray(format_info_binary64, ...)raisesOverflowError: Python int too large to convert to C longwhen NumPy resolves the signed-zeronp.whereoperands. The negative-zero code is 2**63, outside the signed int64 range. This also affects arrays with no zero values and empty arrays because NumPy still resolves the operands for an empty selection.Cast both zero code points to
np.uint64before passing them tonp.where, matching the output array's dtype. Add regression coverage for signed zeros, mixed two-dimensional inputs, inputs without zeros, and empty arrays. The tests compare exact float64 bit patterns and verify output shape and dtype.Fixes #63.