-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from tylerjereddy/treddy_to_device_cpu_cupy
ENH: support CuPy to_device "cpu"
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from ._helpers import import_ | ||
from array_api_compat import to_device, device | ||
|
||
import pytest | ||
import numpy as np | ||
from numpy.testing import assert_allclose | ||
|
||
@pytest.mark.parametrize("library", ["cupy", "numpy", "torch"]) | ||
def test_to_device_host(library): | ||
# different libraries have different semantics | ||
# for DtoH transfers; ensure that we support a portable | ||
# shim for common array libs | ||
# see: https://github.com/scipy/scipy/issues/18286#issuecomment-1527552919 | ||
xp = import_('array_api_compat.' + library) | ||
expected = np.array([1, 2, 3]) | ||
x = xp.asarray([1, 2, 3]) | ||
x = to_device(x, "cpu") | ||
# torch will return a genuine Device object, but | ||
# the other libs will do something different with | ||
# a `device(x)` query; however, what's really important | ||
# here is that we can test portably after calling | ||
# to_device(x, "cpu") to return to host | ||
assert_allclose(x, expected) |