Skip to content

Commit f79a076

Browse files
committed
test: generic_reducer_operation and block_boundary for axis=-1
1 parent b59e428 commit f79a076

File tree

2 files changed

+357
-1016
lines changed

2 files changed

+357
-1016
lines changed
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
from __future__ import annotations
2+
3+
import cupy as cp
4+
import numpy as np
5+
import pytest
6+
7+
import awkward as ak
8+
9+
to_list = ak.operations.to_list
10+
11+
12+
@pytest.fixture(scope="function", autouse=True)
13+
def cleanup_cuda():
14+
yield
15+
cp._default_memory_pool.free_all_blocks()
16+
cp.cuda.Device().synchronize()
17+
18+
19+
def test_block_boundary_sum():
20+
np.random.seed(42)
21+
content = ak.contents.NumpyArray(np.random.randint(3000, size=3000))
22+
cuda_content = ak.to_backend(content, "cuda", highlevel=False)
23+
assert ak.sum(cuda_content, -1, highlevel=False) == ak.sum(
24+
content, -1, highlevel=False
25+
)
26+
27+
offsets = ak.index.Index64(np.array([0, 1, 2998, 3000], dtype=np.int64))
28+
depth1 = ak.contents.ListOffsetArray(offsets, content)
29+
cuda_depth1 = ak.to_backend(depth1, "cuda", highlevel=False)
30+
assert to_list(ak.sum(cuda_depth1, -1, highlevel=False)) == to_list(
31+
ak.sum(depth1, -1, highlevel=False)
32+
)
33+
del cuda_content, cuda_depth1
34+
35+
36+
def test_block_boundary_any():
37+
np.random.seed(42)
38+
content = ak.contents.NumpyArray(np.random.randint(3000, size=3000))
39+
cuda_content = ak.to_backend(content, "cuda", highlevel=False)
40+
assert ak.any(cuda_content, -1, highlevel=False) == ak.any(
41+
content, -1, highlevel=False
42+
)
43+
44+
offsets = ak.index.Index64(np.array([0, 1, 2998, 3000], dtype=np.int64))
45+
depth1 = ak.contents.ListOffsetArray(offsets, content)
46+
cuda_depth1 = ak.to_backend(depth1, "cuda", highlevel=False)
47+
assert to_list(ak.any(cuda_depth1, -1, highlevel=False)) == to_list(
48+
ak.any(depth1, -1, highlevel=False)
49+
)
50+
del cuda_content, cuda_depth1
51+
52+
53+
def test_block_boundary_all():
54+
np.random.seed(42)
55+
content = ak.contents.NumpyArray(np.random.randint(3000, size=3000))
56+
cuda_content = ak.to_backend(content, "cuda", highlevel=False)
57+
assert ak.all(cuda_content, -1, highlevel=False) == ak.all(
58+
content, -1, highlevel=False
59+
)
60+
61+
offsets = ak.index.Index64(np.array([0, 1, 2998, 3000], dtype=np.int64))
62+
depth1 = ak.contents.ListOffsetArray(offsets, content)
63+
cuda_depth1 = ak.to_backend(depth1, "cuda", highlevel=False)
64+
assert to_list(ak.all(cuda_depth1, -1, highlevel=False)) == to_list(
65+
ak.all(depth1, -1, highlevel=False)
66+
)
67+
del cuda_content, cuda_depth1
68+
69+
70+
def test_block_boundary_sum_bool():
71+
np.random.seed(42)
72+
content = ak.contents.NumpyArray(np.random.randint(2, size=3000))
73+
cuda_content = ak.to_backend(content, "cuda", highlevel=False)
74+
assert ak.sum(cuda_content, -1, highlevel=False) == ak.sum(
75+
content, -1, highlevel=False
76+
)
77+
78+
offsets = ak.index.Index64(np.array([0, 1, 2998, 3000], dtype=np.int64))
79+
depth1 = ak.contents.ListOffsetArray(offsets, content)
80+
cuda_depth1 = ak.to_backend(depth1, "cuda", highlevel=False)
81+
assert to_list(ak.sum(cuda_depth1, -1, highlevel=False)) == to_list(
82+
ak.sum(depth1, -1, highlevel=False)
83+
)
84+
del cuda_content, cuda_depth1
85+
86+
87+
def test_block_boundary_max():
88+
np.random.seed(42)
89+
content = ak.contents.NumpyArray(np.random.randint(3000, size=3000))
90+
cuda_content = ak.to_backend(content, "cuda", highlevel=False)
91+
assert ak.max(cuda_content, -1, highlevel=False) == ak.max(
92+
content, -1, highlevel=False
93+
)
94+
95+
offsets = ak.index.Index64(np.array([0, 1, 2998, 3000], dtype=np.int64))
96+
depth1 = ak.contents.ListOffsetArray(offsets, content)
97+
cuda_depth1 = ak.to_backend(depth1, "cuda", highlevel=False)
98+
assert to_list(ak.max(cuda_depth1, -1, highlevel=False)) == to_list(
99+
ak.max(depth1, -1, highlevel=False)
100+
)
101+
del cuda_content, cuda_depth1
102+
103+
104+
def test_block_boundary_min():
105+
np.random.seed(42)
106+
content = ak.contents.NumpyArray(np.random.randint(3000, size=3000))
107+
cuda_content = ak.to_backend(content, "cuda", highlevel=False)
108+
assert ak.min(cuda_content, -1, highlevel=False) == ak.min(
109+
content, -1, highlevel=False
110+
)
111+
112+
offsets = ak.index.Index64(np.array([0, 1, 2998, 3000], dtype=np.int64))
113+
depth1 = ak.contents.ListOffsetArray(offsets, content)
114+
cuda_depth1 = ak.to_backend(depth1, "cuda", highlevel=False)
115+
assert to_list(ak.min(cuda_depth1, -1, highlevel=False)) == to_list(
116+
ak.min(depth1, -1, highlevel=False)
117+
)
118+
del cuda_content, cuda_depth1
119+
120+
121+
def test_block_boundary_count():
122+
np.random.seed(42)
123+
content = ak.contents.NumpyArray(np.random.randint(3000, size=3000))
124+
cuda_content = ak.to_backend(content, "cuda", highlevel=False)
125+
assert ak.count(cuda_content, -1, highlevel=False) == ak.count(
126+
content, -1, highlevel=False
127+
)
128+
129+
offsets = ak.index.Index64(np.array([0, 1, 2998, 3000], dtype=np.int64))
130+
depth1 = ak.contents.ListOffsetArray(offsets, content)
131+
cuda_depth1 = ak.to_backend(depth1, "cuda", highlevel=False)
132+
assert to_list(ak.count(cuda_depth1, -1, highlevel=False)) == to_list(
133+
ak.count(depth1, -1, highlevel=False)
134+
)
135+
del cuda_content, cuda_depth1
136+
137+
138+
def test_block_boundary_count_nonzero():
139+
np.random.seed(42)
140+
content = ak.contents.NumpyArray(np.random.randint(2, size=3000))
141+
cuda_content = ak.to_backend(content, "cuda", highlevel=False)
142+
assert ak.count_nonzero(cuda_content, -1, highlevel=False) == ak.count_nonzero(
143+
content, -1, highlevel=False
144+
)
145+
146+
offsets = ak.index.Index64(np.array([0, 1, 2998, 3000], dtype=np.int64))
147+
depth1 = ak.contents.ListOffsetArray(offsets, content)
148+
cuda_depth1 = ak.to_backend(depth1, "cuda", highlevel=False)
149+
assert to_list(ak.count_nonzero(cuda_depth1, -1, highlevel=False)) == to_list(
150+
ak.count_nonzero(depth1, -1, highlevel=False)
151+
)
152+
del cuda_content, cuda_depth1
153+
154+
155+
def test_block_boundary_prod():
156+
np.random.seed(42)
157+
primes = [x for x in range(2, 30000) if all(x % n != 0 for n in range(2, x))]
158+
content = ak.contents.NumpyArray(primes)
159+
cuda_content = ak.to_backend(content, "cuda", highlevel=False)
160+
assert ak.prod(cuda_content, -1, highlevel=False) == ak.prod(
161+
content, -1, highlevel=False
162+
)
163+
164+
offsets = ak.index.Index64(np.array([0, 1, 2998, 3000], dtype=np.int64))
165+
depth1 = ak.contents.ListOffsetArray(offsets, content)
166+
cuda_depth1 = ak.to_backend(depth1, "cuda", highlevel=False)
167+
assert to_list(ak.prod(cuda_depth1, -1, highlevel=False)) == to_list(
168+
ak.prod(depth1, -1, highlevel=False)
169+
)
170+
del cuda_content, cuda_depth1

0 commit comments

Comments
 (0)