Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bfloat16 & other custom dtypes incompatible with np.save #41

Open
jakevdp opened this issue Mar 23, 2023 · 0 comments
Open

bfloat16 & other custom dtypes incompatible with np.save #41

jakevdp opened this issue Mar 23, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@jakevdp
Copy link
Collaborator

jakevdp commented Mar 23, 2023

from ml_dtypes import bfloat16
import numpy as np

x = np.arange(4, dtype=bfloat16)
np.save('out.npy', x)
print(np.load('out.npy'))
# [b'\x00\x00' b'\x80\x3F' b'\x00\x40' b'\x40\x40']

This is due to the fact that np.save saves the dtype via the kind code, and we chose np.dtype(bfloat16).kind = 'V' because such codes are not extensible in numpy.

When reconstructing the dtype, this is the result:

np.dtype(np.dtype(bfloat16).kind)
# dtype('V')

I don't think this is something that can be fixed without deeper changes to numpy itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant