Skip to content

Fix binary64 ndarray encoding overflow for signed zero - #64

Merged
awf merged 1 commit into
graphcore-research:mainfrom
awf:issue-63-fix
Sep 19, 2026
Merged

awf merged 1 commit into
graphcore-research:mainfrom
awf:issue-63-fix

Conversation

@awf

@awf awf commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

encode_ndarray(format_info_binary64, ...) raises OverflowError: Python int too large to convert to C long when NumPy resolves the signed-zero np.where operands. 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.uint64 before passing them to np.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.

@awf
awf marked this pull request as draft September 18, 2026 15:02
@orlitzky

Copy link
Copy Markdown

There was probably no doubt in your mind, but I can confirm that this does fix my tests.

@awf
awf marked this pull request as ready for review September 19, 2026 09:33
@awf
awf requested a lite review from Copilot September 19, 2026 09:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.uint64 before np.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.

@awf
awf merged commit 9df2a8c into graphcore-research:main Sep 19, 2026
1 of 3 checks passed
@awf

awf commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator Author

There was probably no doubt in your mind, but I can confirm that this does fix my tests.

Thanks!

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.

Test failures on RISC-V

3 participants