libnpy
libnpy copied to clipboard
[Feature Request] float16 support
Can we add half as a dependency to support half precision floating point number? I've done a bit of simple test, it seems work fine.
Have you checked it s compat with np.half ?
import numpy as np
a = np.array([2,2], dtype=np.half)
np.save('f16.npy', a)
I try to avoid adding non-standard dependencies. Let me think about this.
I try to avoid adding non-standard dependencies. Let me think about this.
OK, just let you know, I don't need this anymore, XD
I would still appreciate this new feature. Adding a dep to the half headers is perhaps not necessary anyway.
I have the similar case, but there is a simple way to implement the reader: struct half { uint16_t u; }; // Can be inside namespace npy
Then, add {std::type_index(typeid(half)), {host_endian_char, 'f', sizeof(half)}}, into dtype_map.
Thanks.
A standard conforming way would be:
const std::unordered_map<std::type_index, dtype_t> dtype_map = {
{std::type_index(typeid(float16_t)), {host_endian_char, 'f', sizeof(float16_t)}},
This requires #include <stdfloat>
header, which is a C++23 feature.