@@ -15,8 +15,8 @@ def side_ids(side):
15
15
16
16
17
17
@pytest .mark .parametrize ("side" , [100 , 500 , 1000 ], ids = side_ids )
18
- def test_matmul (benchmark , side , seed ):
19
- if side ** 2 >= 2 ** 26 :
18
+ def test_matmul (benchmark , side , seed , max_size ):
19
+ if side ** 2 >= max_size :
20
20
pytest .skip ()
21
21
rng = np .random .default_rng (seed = seed )
22
22
x = sparse .random ((side , side ), density = DENSITY , random_state = rng )
@@ -29,15 +29,15 @@ def bench():
29
29
x @ y
30
30
31
31
32
- def elemwise_test_name (param ):
32
+ def get_test_id (param ):
33
33
side , rank = param
34
34
return f"{ side = } -{ rank = } "
35
35
36
36
37
- @pytest .fixture (params = itertools .product ([100 , 500 , 1000 ], [1 , 2 , 3 , 4 ]), ids = elemwise_test_name )
38
- def elemwise_args (request , seed ):
37
+ @pytest .fixture (params = itertools .product ([100 , 500 , 1000 ], [1 , 2 , 3 , 4 ]), ids = get_test_id )
38
+ def elemwise_args (request , seed , max_size ):
39
39
side , rank = request .param
40
- if side ** rank >= 2 ** 26 :
40
+ if side ** rank >= max_size :
41
41
pytest .skip ()
42
42
rng = np .random .default_rng (seed = seed )
43
43
shape = (side ,) * rank
@@ -57,9 +57,9 @@ def bench():
57
57
58
58
59
59
@pytest .fixture (params = [100 , 500 , 1000 ], ids = side_ids )
60
- def elemwise_broadcast_args (request , seed ):
60
+ def elemwise_broadcast_args (request , seed , max_size ):
61
61
side = request .param
62
- if side ** 2 >= 2 ** 26 :
62
+ if side ** 2 >= max_size :
63
63
pytest .skip ()
64
64
rng = np .random .default_rng (seed = seed )
65
65
x = sparse .random ((side , 1 , side ), density = DENSITY , random_state = rng )
@@ -77,65 +77,46 @@ def bench():
77
77
f (x , y )
78
78
79
79
80
- @pytest .fixture (params = [100 , 500 , 1000 ], ids = side_ids )
81
- def indexing_args (request , seed ):
82
- side = request .param
83
- if side ** 3 >= 2 ** 26 :
80
+ @pytest .fixture (params = itertools . product ( [100 , 500 , 1000 ], [ 1 , 2 , 3 ]), ids = get_test_id )
81
+ def indexing_args (request , seed , max_size ):
82
+ side , rank = request .param
83
+ if side ** rank >= max_size :
84
84
pytest .skip ()
85
85
rng = np .random .default_rng (seed = seed )
86
+ shape = (side ,) * rank
86
87
87
- return sparse .random (( side , side , side ) , density = DENSITY , random_state = rng )
88
+ return sparse .random (shape , density = DENSITY , random_state = rng )
88
89
89
90
90
91
def test_index_scalar (benchmark , indexing_args ):
91
92
x = indexing_args
92
93
side = x .shape [0 ]
94
+ rank = x .ndim
93
95
94
- x [side // 2 , side // 2 , side // 2 ] # Numba compilation
96
+ x [( side // 2 ,) * rank ] # Numba compilation
95
97
96
98
@benchmark
97
99
def bench ():
98
- x [side // 2 , side // 2 , side // 2 ]
100
+ x [( side // 2 ,) * rank ]
99
101
100
102
101
103
def test_index_slice (benchmark , indexing_args ):
102
104
x = indexing_args
103
105
side = x .shape [0 ]
106
+ rank = x .ndim
104
107
105
- x [: side // 2 ] # Numba compilation
106
-
107
- @benchmark
108
- def bench ():
109
- x [: side // 2 ]
110
-
111
-
112
- def test_index_slice2 (benchmark , indexing_args ):
113
- x = indexing_args
114
- side = x .shape [0 ]
115
-
116
- x [: side // 2 , : side // 2 ] # Numba compilation
117
-
118
- @benchmark
119
- def bench ():
120
- x [: side // 2 , : side // 2 ]
121
-
122
-
123
- def test_index_slice3 (benchmark , indexing_args ):
124
- x = indexing_args
125
- side = x .shape [0 ]
126
-
127
- x [: side // 2 , : side // 2 , : side // 2 ] # Numba compilation
108
+ x [(slice (side // 2 ),) * rank ] # Numba compilation
128
109
129
110
@benchmark
130
111
def bench ():
131
- x [: side // 2 , : side // 2 , : side // 2 ]
112
+ x [( slice ( side // 2 ),) * rank ]
132
113
133
114
134
115
def test_index_fancy (benchmark , indexing_args , seed ):
135
116
x = indexing_args
136
117
side = x .shape [0 ]
137
118
rng = np .random .default_rng (seed = seed )
138
- index = rng .integers (0 , side , side // 2 )
119
+ index = rng .integers (0 , side , size = ( side // 2 ,) )
139
120
140
121
x [index ] # Numba compilation
141
122
0 commit comments