Skip to content

Arrays created with from_dlpack have a different device? #99

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

Closed
mdhaber opened this issue Nov 21, 2024 · 0 comments · Fixed by #108
Closed

Arrays created with from_dlpack have a different device? #99

mdhaber opened this issue Nov 21, 2024 · 0 comments · Fixed by #108

Comments

@mdhaber
Copy link

mdhaber commented Nov 21, 2024

It seems that when a strict array is created using from_dlpack, its device property is not set as I would expect. Consequently, strict arrays created with from_dlpack cannot operate with strict arrays that were not created with from_dlpack.

import array_api_strict as xp
x = xp.asarray([1, 2, 3])
y = xp.from_dlpack(x)
x * y
# ValueError: Arrays from two different devices (array_api_strict.Device('CPU_DEVICE') and <object object at 0x111f86f90>) can not be combined.

x.device  # array_api_strict.Device('CPU_DEVICE')
y.device  # <object at 0x111f86f90>

I actually encountered this problem when from_dlpack is used on a NumPy array.

import numpy as np
import array_api_strict as xp
x = xp.asarray([1, 2, 3])
y = xp.from_dlpack(np.asarray([2, 3, 4]))
x * y  # same problem

Crossref scipy/scipy#21890

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.

1 participant