-
Notifications
You must be signed in to change notification settings - Fork 383
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Feature Request
Add float16 support to Fory Python runtime and codegen using numpy.float16 as the public scalar type, plus array support for efficient serialization.
Is your feature request related to a problem? Please describe
We want to use float16 in FDL to reduce payload size and memory footprint, and to interoperate with ML/graphics ecosystems where half precision is common. Python currently lacks a first-class float16 primitive in Fory.
Describe the solution you'd like
1) FDL / Type System
- Introduce
float16as a new primitive type in FDL. - Allow
float16in message fields, repeated fields, map values, and unions (where primitives are allowed).
2) Wire Format / Serialization Semantics
- Encode
float16as 2 bytes representing the raw IEEE 754 binary16 bit pattern. - Endianness must match existing float32/float64 behavior.
- NaN/Inf/±0/subnormal must round-trip correctly at the bit level (document NaN policy if canonicalized).
3) Python Runtime (core requirement)
Use numpy.float16 as the public scalar type.
3.1 Type definition
- Public APIs should accept/return
numpy.float16(not rawuint16bits). - No custom float16 class should be required.
3.2 Arrays / float16_array
- For repeated
float16, supportnumpy.ndarraywithdtype=float16as a fast path. - Define a
float16_arraycontainer as a packed array of 16-bit values and map it tonumpy.ndarray(dtype=float16).
3.3 Serialization boundary
- Serializer/deserializer should read/write raw 16-bit patterns from
numpy.float16values and arrays. - Avoid per-element Python overhead when handling arrays.
4) Codegen requirement (Python)
- Generated fields for
float16should usenumpy.float16in type hints. - Generated fields for
float16_arrayorrepeated float16should usenumpy.ndarray(dtype=float16) where possible.
5) Compiler/Reflection integration
- Ensure reflection/dynamic serialization recognizes
numpy.float16as thefloat16primitive.
6) Tests
- Conversion and round-trip tests for scalars (±0, ±Inf, NaN, subnormals, max/min normal).
- Array serialization tests using
numpy.ndarray. - Cross-language golden tests can be added later.
Describe alternatives you've considered
- Use a custom Python
Float16class.
- Rejected:
numpy.float16is the de-facto standard and already optimized.
Additional context
This issue is the Python counterpart of the per-language float16 work.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request