11import numpy as np
22import pytest
3+
34import cunumpy as xp
45
6+
57def test_to_numpy ():
68 arr = xp .array ([1 , 2 , 3 ])
79 # Even if it's already numpy, to_numpy should work
810 arr_np = xp .to_numpy (arr )
911 assert isinstance (arr_np , np .ndarray )
1012 assert np .array_equal (arr_np , [1 , 2 , 3 ])
1113
14+
1215def test_to_cunumpy ():
1316 arr = np .array ([1 , 2 , 3 ])
1417 arr_xp = xp .to_cunumpy (arr )
1518 # Backend is numpy in tests usually
1619 assert isinstance (arr_xp , (np .ndarray , xp .ndarray ))
1720
21+
1822def test_get_backend_and_is_gpu_cpu ():
1923 arr = np .array ([1 , 2 , 3 ])
2024 assert xp .get_backend (arr ) == "numpy"
2125 assert xp .is_gpu (arr ) is False
2226 assert xp .is_cpu (arr ) is True
2327
28+
2429def test_use_backend ():
2530 # Initial backend should be numpy (default) in this test environment
2631 assert "numpy" in xp .xp .__name__
@@ -32,6 +37,7 @@ def test_use_backend():
3237
3338 assert "numpy" in xp .xp .__name__
3439
40+
3541def test_set_backend ():
3642 # Set to numpy
3743 xp .set_backend ("numpy" )
@@ -45,6 +51,7 @@ def test_set_backend():
4551 arr2 = xp .array ([2 ])
4652 assert arr2 is not None
4753
54+
4855def test_backend_bools ():
4956 with xp .use_backend ("numpy" ):
5057 assert xp .numpy_backend is True
0 commit comments