@@ -217,9 +217,6 @@ def all_floating_dtypes() -> SearchStrategy[DataType]:
217
217
# Size to use for 2-dim arrays
218
218
SQRT_MAX_ARRAY_SIZE = int (math .sqrt (MAX_ARRAY_SIZE ))
219
219
220
- # np.prod and others have overflow and math.prod is Python 3.8+ only
221
- def prod (seq ):
222
- return reduce (mul , seq , 1 )
223
220
224
221
# hypotheses.strategies.tuples only generates tuples of a fixed size
225
222
def tuples (elements , * , min_size = 0 , max_size = None , unique_by = None , unique = False ):
@@ -233,7 +230,7 @@ def shapes(**kw):
233
230
kw .setdefault ('min_dims' , 0 )
234
231
kw .setdefault ('min_side' , 0 )
235
232
return xps .array_shapes (** kw ).filter (
236
- lambda shape : prod (i for i in shape if i ) < MAX_ARRAY_SIZE
233
+ lambda shape : math . prod (i for i in shape if i ) < MAX_ARRAY_SIZE
237
234
)
238
235
239
236
@@ -245,7 +242,7 @@ def matrix_shapes(draw, stack_shapes=shapes()):
245
242
stack_shape = draw (stack_shapes )
246
243
mat_shape = draw (xps .array_shapes (max_dims = 2 , min_dims = 2 ))
247
244
shape = stack_shape + mat_shape
248
- assume (prod (i for i in shape if i ) < MAX_ARRAY_SIZE )
245
+ assume (math . prod (i for i in shape if i ) < MAX_ARRAY_SIZE )
249
246
return shape
250
247
251
248
square_matrix_shapes = matrix_shapes ().filter (lambda shape : shape [- 1 ] == shape [- 2 ])
@@ -290,7 +287,7 @@ def mutually_broadcastable_shapes(
290
287
)
291
288
.map (lambda BS : BS .input_shapes )
292
289
.filter (lambda shapes : all (
293
- prod (i for i in s if i > 0 ) < MAX_ARRAY_SIZE for s in shapes
290
+ math . prod (i for i in s if i > 0 ) < MAX_ARRAY_SIZE for s in shapes
294
291
))
295
292
)
296
293
@@ -321,7 +318,7 @@ def positive_definite_matrices(draw, dtypes=floating_dtypes):
321
318
base_shape = draw (shapes ())
322
319
n = draw (integers (0 , 8 )) # 8 is an arbitrary small but interesting-enough value
323
320
shape = base_shape + (n , n )
324
- assume (prod (i for i in shape if i ) < MAX_ARRAY_SIZE )
321
+ assume (math . prod (i for i in shape if i ) < MAX_ARRAY_SIZE )
325
322
dtype = draw (dtypes )
326
323
return broadcast_to (eye (n , dtype = dtype ), shape )
327
324
0 commit comments