Skip to content

Arrays created with from_dlpack have a different device? #99

Closed
@mdhaber

Description

@mdhaber

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions