Use Half-precision (float16) data
mainHalf-precision floats (dtype: '<e') are supported via the Float16Array in browsers that support it.
- Reading: If the runtime supports
Float16Array, data is loaded into it. If not, it returns aUint8Arrayand logs a warning. - Writing: You can pass a
Float16Arraydirectly, or pass plain numbers with an explicitdtype: '<e', in which case values are rounded to the nearest representable half.
Note: bfloat16 is also stored as a 2-byte float but currently lacks a native JS container; these will return raw bytes.
// Writing from Float16Array
new_file.create_dataset({name: "half", data: new Float16Array([1.5, -2.5])});
// Writing plain numbers with explicit dtype (auto-rounding)
new_file.create_dataset({name: "rounded", data: [0.1], dtype: '<e'});