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

TST: at: add test for device #180

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion tests/test_at.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from array_api_extra._lib._at import _AtOp
from array_api_extra._lib._testing import xp_assert_equal
from array_api_extra._lib._utils._compat import array_namespace, is_writeable_array
from array_api_extra._lib._utils._typing import Array, SetIndex
from array_api_extra._lib._utils._compat import device as get_device
from array_api_extra._lib._utils._typing import Array, Device, SetIndex
from array_api_extra.testing import lazy_xp_function

pytestmark = [
Expand Down Expand Up @@ -327,3 +328,15 @@ def test_gh134(xp: ModuleType, bool_mask: bool, copy: bool | None):
idx = xp.asarray(True) if bool_mask else ()
z = at_op(y, idx, _AtOp.SET, 1, copy=copy)
xp_assert_equal(z, xp.asarray(1, dtype=x.dtype))


def test_device(xp: ModuleType, device: Device):
x = xp.asarray([1, 2, 3], device=device)

y = xp.asarray([4, 5], device=device)
z = at(x)[:2].set(y)
assert get_device(z) == get_device(x)

idx = xp.asarray([True, False, True], device=device)
z = at(x)[idx].set(4)
assert get_device(z) == get_device(x)