Consider the following two arrays:
>>> import array_api_strict as xp
>>> a = xp.ones(10, device=xp.Device("device2"))
>>> b = 2 * xp.ones(10)
As expected, it's not possible to run operations that combine two such arrays because they live on different devices:
>>> a + b
Traceback (most recent call last):
Cell In[23], line 1
a + b
File ~/miniforge3/envs/dev/lib/python3.13/site-packages/array_api_strict/_array_object.py:545 in __add__
self._check_type_device(other)
File ~/miniforge3/envs/dev/lib/python3.13/site-packages/array_api_strict/_array_object.py:241 in _check_type_device
raise ValueError(f"Arrays from two different devices ({self.device} and {other.device}) can not be combined.")
ValueError: Arrays from two different devices (array_api_strict.Device('device2') and array_api_strict.Device('CPU_DEVICE')) can not be combined.
However, doing assignment works without raising an exception despite the fact that this causes an implicit data transfer between devices:
>>> b[:5] = a[:5]
>>> b
Array([1., 1., 1., 1., 1., 2., 2., 2., 2.,
2.], dtype=array_api_strict.float64)
Shouldn't the __setitem__ call raise in this case?
Consider the following two arrays:
As expected, it's not possible to run operations that combine two such arrays because they live on different devices:
However, doing assignment works without raising an exception despite the fact that this causes an implicit data transfer between devices:
Shouldn't the
__setitem__call raise in this case?