This repository was archived by the owner on Jan 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_io.py
More file actions
57 lines (50 loc) · 1.73 KB
/
test_io.py
File metadata and controls
57 lines (50 loc) · 1.73 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
51
52
53
54
55
56
57
import numpy as np
import pytest
from utils import device
import sharpy as sp
class TestIO:
@pytest.mark.parametrize("backend", ["opencl:", "level-zero:", "cuda:", ""])
@pytest.mark.parametrize("device", ["host", "gpu", "cpu", "accelerator"])
@pytest.mark.parametrize("subdev", [":2", ""])
def test_device_input_valid(self, backend, device, subdev):
a = sp.ones((4,), device=f"{backend}{device}{subdev}")
assert a.size == 4
@pytest.mark.parametrize(
"device",
[
"opencl3:gpu",
"opencl:hostx",
"opencl:cpu:r",
"opencl:gpu::1",
"opencl::gpu:1",
],
)
def test_device_input_invalid(self, device):
with pytest.raises(ValueError, match="Invalid device string: *"):
sp.ones((4,), device=device)
def test_to_numpy2d(self):
a = sp.reshape(
sp.arange(0, 110, 1, dtype=sp.float32, device=device), [11, 10]
)
b = sp.to_numpy(a)
c = np.sum(b)
v = np.sum(np.reshape(np.arange(0, 110, 1, dtype=np.float32), (11, 10)))
assert float(c) == v
def test_to_numpy1d(self):
a = sp.arange(0, 110, 1, dtype=sp.float32, device=device)
b = sp.to_numpy(a)
c = np.sum(b)
v = np.sum(np.arange(0, 110, 1, dtype=np.float32))
assert float(c) == v
def test_to_numpy_strided(self):
a = sp.reshape(
sp.arange(0, 110, 1, dtype=sp.float32, device=device), [11, 10]
)
b = sp.to_numpy(a[4:12:2, 1:11:3])
c = np.sum(b)
v = np.sum(
np.reshape(np.arange(0, 110, 1, dtype=np.float32), (11, 10))[
4:12:2, 1:11:3
]
)
assert float(c) == v