jax-ml / jax-ml/ml_dtypes

`data` attribute raises a `ValueError`

Open
#80 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
361
Forks
60
Avg merge
18h 41m
Merged PRs (30d)
3

Description

[numpy.ndarray.data](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.data.html) attribute doesn't work with ml_dtypes.

bfloat16 example:
```
from ml_dtypes import bfloat16
x = np.array([0], dtype=bfloat16)
x.data
# ValueError: cannot include dtype 'E' in a buffer
```

float8_e4m3fnuz example:
```
from ml_dtypes import float8_e4m3fnuz
x = np.array([0], dtype=float8_e4m3fnuz)
x.data
# ValueError: cannot include dtype 'G' in a buffer
```

Current workaround is by using the `__array_interface__` attribute:
```
x.__array_interface__['data'][0]
```

ml_dtypes version: 0.2.0
numpy version: 1.24.3

Contributor guide

Open the contributing guide

Research direction

Reproduce the bfloat16 and float8_e4m3fnuz examples from the issue with ml_dtypes 0.2.0 and NumPy 1.24.3, then inspect the ml_dtypes implementation involved in exposing these dtypes to NumPy buffers. Done means the x.data attribute works for both examples without the reported ValueError, while the existing __array_interface__ workaround remains unnecessary.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.