miantalha45 opened a new pull request, #3527:
URL: https://github.com/apache/fory/pull/3527
## Description
This PR introduces the `bfloat16` and `bfloat16_array` primitives to the
Fory Dart runtime, fulfilling the requirement for a memory-efficient brain
floating-point formulation commonly used in ML/AI workflows. It strictly
mirrors the structural implementations of the existing `float16` work.
Fixes #3287
## Changes Made
1. **Dart Runtime Type Definitions**:
- Introduced `BFloat16` as a strongly-typed subclass of the `FixedNum`
base class, safely wrapping the 16-bit integer representing the representation
bits without exposing raw `uint16` in public math APIs.
- Implemented `BFloat16Array` as a packed contiguous array collection
optimally backed by `Uint16List`.
2. **IEEE 754 Conversions**:
- Implemented `BFloat16.fromFloat32` and `toFloat32()` doing bitwise
round-to-nearest and ties-to-even operations over proxy memory layers
(`Float32List` / `Uint32List.view`) mapped exactly to cross-language canonical
IEEE 754 bfloat16 bit representations.
- Exposed explicit scalar getters (`value`, `toBits()`, `fromBits()`).
3. **Reflection & Serialization Integration**:
- Registered `_BFloat16SerializerCache` inside
`primitive_type_serializer.dart` directly wiring to `BFloat16Serializer`.
- Populated the `BFloat16` serialization route inside the
`typeToTypeInfo` registry in `serializer_pool.dart`.
- Exported the new datatypes in the main `fory.dart` barrel file.
4. **Testing**:
- Added rigorous tests targeting scalar numeric conversions (validating
mappings like `0x3f80 == 1.0`).
- Covered object equality, hashcode matching, and `BFloat16Array` dynamic
generic injections handling `List<dynamic>` scaling natively.
## Type of change
- [x] New feature (non-breaking change which adds functionality)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Performance optimization
- [ ] Documentation update
## Checklist:
- [x] I have performed a self-review of my own code
- [x] I have added standard ASF license headers and Dartdoc comments (`///`)
- [x] I have added necessary unit tests confirming the bitwise boundaries
- [x] Existing and new tests pass locally (`dart test`)
### AI Assistance Checklist
- [x] Substantial AI assistance was used in this PR (yes)
- [x] I included the standardized AI Usage Disclosure block below
- [x] I can explain and defend all important changes without AI help
- [x] I reviewed AI-assisted code changes line by line before submission
- [x] I ran adequate human verification and recorded evidence (local/CI
checks, pass/fail summary, and review confirmation)
- [x] I added/updated tests and specs where required
- [x] I validated protocol/performance impacts with evidence when applicable
- [x] I verified licensing and provenance compliance
AI Usage Disclosure
- substantial_ai_assistance: yes
- scope: <design drafting | code drafting>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]