Skip to content

MOD-14559 Fix float serialization precision for typed FPHA arrays#19

Open
AvivDavid23 wants to merge 4 commits intomasterfrom
MOD-14559
Open

MOD-14559 Fix float serialization precision for typed FPHA arrays#19
AvivDavid23 wants to merge 4 commits intomasterfrom
MOD-14559

Conversation

@AvivDavid23
Copy link

@AvivDavid23 AvivDavid23 commented Mar 18, 2026

When serializing typed float arrays, values were promoted to f64 (via INumber) before being passed to serde_json's serialize_f64. This caused serde_json's ryu formatter to produce unnecessarily long decimal strings, because ryu needs more digits to uniquely identify a value among all f64s than among all f32s.

For example, 0.3 stored in an F32 array would serialize as "0.30000001192092896" instead of "0.3".

The fix bypasses the IValue/INumber conversion for F32/F16/BF16 typed arrays during serialization, instead passing the raw float values directly to serde. This routes F32 values through serialize_f32 (and F16/BF16 through serialize_f32 via f32::from()), where ryu's f32 algorithm produces the shortest string that round-trips through f32 — matching user expectations.


Note

Medium Risk
Changes the exact JSON text produced for typed float arrays (especially f16/bf16/f32), which may affect snapshot tests or consumers relying on prior formatting, but it is constrained to serialization output.

Overview
Improves IArray JSON serialization for typed float arrays to avoid promoting values through INumber/f64, which previously caused overly long decimal strings.

ArraySliceRef::F32 now serializes elements as f32, and ArraySliceRef::F16/BF16 use a new find_shortest_roundtrip_f64 helper to pick the shortest decimal that round-trips through the half type before emitting via serialize_f64. Adds focused tests to ensure short representations and round-trip stability across F16/BF16/F32/F64.

Written by Cursor Bugbot for commit 2141ecf. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

@AvivDavid23 AvivDavid23 requested a review from gabsow March 19, 2026 07:04
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.

1 participant