Skip to content

Commit a7689e1

Browse files
authored
test: Added gcxs to benchmarks to be tested with CodSpeed (#748)
1 parent 59ed2b7 commit a7689e1

File tree

1 file changed

+69
-21
lines changed

1 file changed

+69
-21
lines changed

benchmarks/test_benchmark_coo.py

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@
1010
DENSITY = 0.01
1111

1212

13-
def side_ids(side):
14-
return f"{side=}"
13+
def format_id(format):
14+
return f"{format=}"
1515

1616

17-
@pytest.mark.parametrize("side", [100, 500, 1000], ids=side_ids)
18-
def test_matmul(benchmark, side, seed, max_size):
19-
if side**2 >= max_size:
17+
@pytest.mark.parametrize("format", ["coo", "gcxs"])
18+
def test_matmul(benchmark, sides, format, seed, max_size, ids=format_id):
19+
m, n, p = sides
20+
21+
if m * n >= max_size or n * p >= max_size:
2022
pytest.skip()
23+
2124
rng = np.random.default_rng(seed=seed)
22-
x = sparse.random((side, side), density=DENSITY, random_state=rng)
23-
y = sparse.random((side, side), density=DENSITY, random_state=rng)
25+
x = sparse.random((m, n), density=DENSITY, format=format, random_state=rng)
26+
y = sparse.random((n, p), density=DENSITY, format=format, random_state=rng)
2427

2528
x @ y # Numba compilation
2629

@@ -29,20 +32,20 @@ def bench():
2932
x @ y
3033

3134

32-
def get_test_id(param):
33-
side, rank = param
34-
return f"{side=}-{rank=}"
35+
def get_test_id(params):
36+
side, rank, format = params
37+
return f"{side=}-{rank=}-{format=}"
3538

3639

37-
@pytest.fixture(params=itertools.product([100, 500, 1000], [1, 2, 3, 4]), ids=get_test_id)
40+
@pytest.fixture(params=itertools.product([100, 500, 1000], [1, 2, 3, 4], ["coo", "gcxs"]), ids=get_test_id)
3841
def elemwise_args(request, seed, max_size):
39-
side, rank = request.param
42+
side, rank, format = request.param
4043
if side**rank >= max_size:
4144
pytest.skip()
4245
rng = np.random.default_rng(seed=seed)
4346
shape = (side,) * rank
44-
x = sparse.random(shape, density=DENSITY, random_state=rng)
45-
y = sparse.random(shape, density=DENSITY, random_state=rng)
47+
x = sparse.random(shape, density=DENSITY, format=format, random_state=rng)
48+
y = sparse.random(shape, density=DENSITY, format=format, random_state=rng)
4649
return x, y
4750

4851

@@ -56,14 +59,19 @@ def bench():
5659
f(x, y)
5760

5861

59-
@pytest.fixture(params=[100, 500, 1000], ids=side_ids)
62+
def get_elemwise_ids(params):
63+
side, format = params
64+
return f"{side=}-{format=}"
65+
66+
67+
@pytest.fixture(params=itertools.product([100, 500, 1000], ["coo", "gcxs"]), ids=get_elemwise_ids)
6068
def elemwise_broadcast_args(request, seed, max_size):
61-
side = request.param
69+
side, format = request.param
6270
if side**2 >= max_size:
6371
pytest.skip()
6472
rng = np.random.default_rng(seed=seed)
65-
x = sparse.random((side, 1, side), density=DENSITY, random_state=rng)
66-
y = sparse.random((side, side), density=DENSITY, random_state=rng)
73+
x = sparse.random((side, 1, side), density=DENSITY, format=format, random_state=rng)
74+
y = sparse.random((side, side), density=DENSITY, format=format, random_state=rng)
6775
return x, y
6876

6977

@@ -77,15 +85,15 @@ def bench():
7785
f(x, y)
7886

7987

80-
@pytest.fixture(params=itertools.product([100, 500, 1000], [1, 2, 3]), ids=get_test_id)
88+
@pytest.fixture(params=itertools.product([100, 500, 1000], [1, 2, 3], ["coo", "gcxs"]), ids=get_test_id)
8189
def indexing_args(request, seed, max_size):
82-
side, rank = request.param
90+
side, rank, format = request.param
8391
if side**rank >= max_size:
8492
pytest.skip()
8593
rng = np.random.default_rng(seed=seed)
8694
shape = (side,) * rank
8795

88-
return sparse.random(shape, density=DENSITY, random_state=rng)
96+
return sparse.random(shape, density=DENSITY, format=format, random_state=rng)
8997

9098

9199
def test_index_scalar(benchmark, indexing_args):
@@ -123,3 +131,43 @@ def test_index_fancy(benchmark, indexing_args, seed):
123131
@benchmark
124132
def bench():
125133
x[index]
134+
135+
136+
def get_sides_ids(param):
137+
m, n, p = param
138+
return f"{m=}-{n=}-{p=}"
139+
140+
141+
@pytest.fixture(params=itertools.product([200, 500, 1000], [200, 500, 1000], [200, 500, 1000]), ids=get_sides_ids)
142+
def sides(request):
143+
m, n, p = request.param
144+
return m, n, p
145+
146+
147+
@pytest.fixture(params=([(0, "coo"), (0, "gcxs"), (1, "gcxs")]), ids=["coo", "gcxs-0-axis", "gcxs-1-axis"])
148+
def densemul_args(request, sides, seed, max_size):
149+
compressed_axis, format = request.param
150+
m, n, p = sides
151+
if m * n >= max_size or n * p >= max_size:
152+
pytest.skip()
153+
rng = np.random.default_rng(seed=seed)
154+
if format == "coo":
155+
x = sparse.random((m, n), density=DENSITY / 10, format=format, random_state=rng)
156+
else:
157+
x = sparse.random((m, n), density=DENSITY / 10, format=format, random_state=rng).change_compressed_axes(
158+
(compressed_axis,)
159+
)
160+
t = rng.random((n, p))
161+
162+
return x, t
163+
164+
165+
def test_gcxs_dot_ndarray(benchmark, densemul_args):
166+
x, t = densemul_args
167+
168+
# Numba compilation
169+
x @ t
170+
171+
@benchmark
172+
def bench():
173+
x @ t

0 commit comments

Comments
 (0)