@@ -94,6 +94,14 @@ def reduc_nojit(a, b, c):
94
94
return np .sum (((a ** 3 + np .sin (a * 2 )) < c ) & (b > 0 ), axis = 1 )
95
95
96
96
97
+ def reduc_mean_nojit (a , b , c ):
98
+ return np .mean (((a ** 3 + np .sin (a * 2 )) < c ) & (b > 0 ), axis = 1 )
99
+
100
+
101
+ def reduc_std_nojit (a , b , c ):
102
+ return np .std (((a ** 3 + np .sin (a * 2 )) < c ) & (b > 0 ), axis = 1 )
103
+
104
+
97
105
@blosc2 .jit
98
106
def reduc_jit (a , b , c ):
99
107
return np .sum (((a ** 3 + np .sin (a * 2 )) < c ) & (b > 0 ), axis = 1 )
@@ -125,6 +133,22 @@ def reduc_jit_out(a, b, c):
125
133
np .testing .assert_equal (out [...], d_nojit [...])
126
134
127
135
136
+ def test_reduc_mean_out (sample_data ):
137
+ a , b , c , shape , cshape , dtype = sample_data
138
+ d_nojit = reduc_mean_nojit (a , b , c )
139
+
140
+ # Testing jit decorator with an out param via the reduction function
141
+ out = np .zeros ((shape [0 ],), dtype = np .float64 )
142
+
143
+ # Note that out does not work with reductions as the last function call
144
+ @blosc2 .jit
145
+ def reduc_mean_jit_out (a , b , c ):
146
+ return np .mean (((a ** 3 + np .sin (a * 2 )) < c ) & (b > 0 ), axis = 1 , out = out )
147
+
148
+ d_jit = reduc_mean_jit_out (a , b , c )
149
+ np .testing .assert_equal (out [...], d_nojit [...])
150
+
151
+
128
152
def test_reduc_kwargs (sample_data ):
129
153
a , b , c , shape , cshape , dtype = sample_data
130
154
d_nojit = reduc_nojit (a , b , c )
@@ -142,3 +166,22 @@ def reduc_jit_cparams(a, b, c):
142
166
assert d_jit .schunk .cparams .clevel == 1
143
167
assert d_jit .schunk .cparams .codec == blosc2 .Codec .LZ4
144
168
assert d_jit .schunk .cparams .filters == [blosc2 .Filter .BITSHUFFLE ] + [blosc2 .Filter .NOFILTER ] * 5
169
+
170
+
171
+ def test_reduc_std_kwargs (sample_data ):
172
+ a , b , c , shape , cshape , dtype = sample_data
173
+ d_nojit = reduc_std_nojit (a , b , c )
174
+
175
+ # Testing jit decorator with kwargs via an out param in the reduction function
176
+ cparams = blosc2 .CParams (clevel = 1 , codec = blosc2 .Codec .LZ4 , filters = [blosc2 .Filter .BITSHUFFLE ])
177
+ out = blosc2 .zeros ((shape [0 ],), dtype = np .float64 , cparams = cparams )
178
+
179
+ @blosc2 .jit
180
+ def reduc_std_jit_cparams (a , b , c ):
181
+ return np .std (((a ** 3 + np .sin (a * 2 )) < c ) & (b > 0 ), axis = 1 , out = out )
182
+
183
+ d_jit = reduc_std_jit_cparams (a , b , c )
184
+ np .testing .assert_equal (d_jit [...], d_nojit [...])
185
+ assert d_jit .schunk .cparams .clevel == 1
186
+ assert d_jit .schunk .cparams .codec == blosc2 .Codec .LZ4
187
+ assert d_jit .schunk .cparams .filters == [blosc2 .Filter .BITSHUFFLE ] + [blosc2 .Filter .NOFILTER ] * 5
0 commit comments