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

BUG,ENH: DLPack will refuse to export certain strided arrays that could be exported #20336

Closed
seberg opened this issue Nov 9, 2021 · 1 comment · Fixed by #21132
Closed

Comments

@seberg
Copy link
Member

seberg commented Nov 9, 2021

The following array cannot be exported by DLPack currently, but would be valid. This is very obscure though:

# Not contiguous array (and not size 1) which has strides that along a dimension of size 1, so that they do not matter:
arr = np.ndarray(dtype="f8", strides=(4, 8), shape=(1, 10), buffer=np.ones(1000, dtype="uint8"))
arr.__dlpack__()  # could be exported, but fails.

I expected it to be easier to achieve, but arr.view only works with C-contiguous arrays.

EDIT: Honestly, if someone ever is tempted to just close this, fine with me (although fixing is probably also easy).

@tirthasheshpatel
Copy link
Contributor

tirthasheshpatel commented Feb 28, 2022

Your example works for me. The strides % itemsize check is only done for non-c-contiguous arrays. So, for example, this fails:

>>> x = np.ndarray(dtype='f8', shape=(10,5,1), strides=(8,80,4), buffer=np.ones(1000, dtype=np.uint8), order='F')
>>> y = np._from_dlpack(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: DLPack only supports strides which are a multiple of itemsize.

But it'd be nice to be able to export arrays irrespective of strides if they only have one element in some dimension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants