-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cupy.py
More file actions
50 lines (34 loc) · 1.13 KB
/
Copy pathtest_cupy.py
File metadata and controls
50 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import numpy as np
import pytest
import cunumpy as xp
def test_to_cupy_available():
if not xp.cupy_available():
pytest.skip("CuPy not installed or not functional")
import cupy as cp
with xp.use_backend("cupy"):
arr = np.array([1, 2, 3])
arr_cp = xp.to_cupy(arr)
assert isinstance(arr_cp, cp.ndarray)
def test_to_cupy_not_available():
if xp.cupy_available():
pytest.skip("CuPy is installed and functional, cannot test missing cupy error")
with xp.use_backend("cupy"):
arr = np.array([1, 2, 3])
with pytest.raises(ImportError):
xp.to_cupy(arr)
def test_synchronize():
# Should not crash on any backend
xp.synchronize()
with xp.use_backend("numpy"):
xp.synchronize()
with xp.use_backend("cupy"):
xp.synchronize()
def test_xp_array_cupy():
if not xp.cupy_available():
pytest.skip("CuPy not installed or not functional")
import cupy as cp
with xp.use_backend("cupy"):
arr = xp.array([1, 2])
arr *= 2
assert isinstance(arr, cp.ndarray)
assert cp.asnumpy(arr).tolist() == [2, 4]