31
31
]
32
32
33
33
34
- def _get_metric_params_list (metric : str , n_features : int ):
34
+ def _get_metric_params_list (metric : str , n_features : int , seed : int = 1 ):
35
35
"""Return list of dummy DistanceMetric kwargs for tests."""
36
36
37
37
# Distinguishing on cases not to compute unneeded datastructures.
38
- rng = np .random .RandomState (1 )
38
+ rng = np .random .RandomState (seed )
39
39
40
40
if metric == "minkowski" :
41
41
minkowski_kwargs = [dict (p = 1.5 ), dict (p = 2 ), dict (p = 3 ), dict (p = np .inf )]
@@ -217,23 +217,22 @@ def test_radius_neighborhood_factory_method_wrong_usages():
217
217
)
218
218
219
219
220
- @pytest .mark .parametrize ("seed" , range (5 ))
221
220
@pytest .mark .parametrize ("n_samples" , [100 , 1000 ])
222
221
@pytest .mark .parametrize ("chunk_size" , [50 , 512 , 1024 ])
223
222
@pytest .mark .parametrize (
224
223
"PairwiseDistancesReduction" ,
225
224
[PairwiseDistancesArgKmin , PairwiseDistancesRadiusNeighborhood ],
226
225
)
227
226
def test_chunk_size_agnosticism (
227
+ global_random_seed ,
228
228
PairwiseDistancesReduction ,
229
- seed ,
230
229
n_samples ,
231
230
chunk_size ,
232
231
n_features = 100 ,
233
232
dtype = np .float64 ,
234
233
):
235
234
# Results should not depend on the chunk size
236
- rng = np .random .RandomState (seed )
235
+ rng = np .random .RandomState (global_random_seed )
237
236
spread = 100
238
237
X = rng .rand (n_samples , n_features ).astype (dtype ) * spread
239
238
Y = rng .rand (n_samples , n_features ).astype (dtype ) * spread
@@ -263,23 +262,22 @@ def test_chunk_size_agnosticism(
263
262
ASSERT_RESULT [PairwiseDistancesReduction ](ref_dist , dist , ref_indices , indices )
264
263
265
264
266
- @pytest .mark .parametrize ("seed" , range (5 ))
267
265
@pytest .mark .parametrize ("n_samples" , [100 , 1000 ])
268
266
@pytest .mark .parametrize ("chunk_size" , [50 , 512 , 1024 ])
269
267
@pytest .mark .parametrize (
270
268
"PairwiseDistancesReduction" ,
271
269
[PairwiseDistancesArgKmin , PairwiseDistancesRadiusNeighborhood ],
272
270
)
273
271
def test_n_threads_agnosticism (
272
+ global_random_seed ,
274
273
PairwiseDistancesReduction ,
275
- seed ,
276
274
n_samples ,
277
275
chunk_size ,
278
276
n_features = 100 ,
279
277
dtype = np .float64 ,
280
278
):
281
279
# Results should not depend on the number of threads
282
- rng = np .random .RandomState (seed )
280
+ rng = np .random .RandomState (global_random_seed )
283
281
spread = 100
284
282
X = rng .rand (n_samples , n_features ).astype (dtype ) * spread
285
283
Y = rng .rand (n_samples , n_features ).astype (dtype ) * spread
@@ -308,23 +306,22 @@ def test_n_threads_agnosticism(
308
306
309
307
# TODO: Remove filterwarnings in 1.3 when wminkowski is removed
310
308
@pytest .mark .filterwarnings ("ignore:WMinkowskiDistance:FutureWarning:sklearn" )
311
- @pytest .mark .parametrize ("seed" , range (5 ))
312
309
@pytest .mark .parametrize ("n_samples" , [100 , 1000 ])
313
310
@pytest .mark .parametrize ("metric" , PairwiseDistancesReduction .valid_metrics ())
314
311
@pytest .mark .parametrize (
315
312
"PairwiseDistancesReduction" ,
316
313
[PairwiseDistancesArgKmin , PairwiseDistancesRadiusNeighborhood ],
317
314
)
318
315
def test_strategies_consistency (
316
+ global_random_seed ,
319
317
PairwiseDistancesReduction ,
320
318
metric ,
321
319
n_samples ,
322
- seed ,
323
320
n_features = 10 ,
324
321
dtype = np .float64 ,
325
322
):
326
323
327
- rng = np .random .RandomState (seed )
324
+ rng = np .random .RandomState (global_random_seed )
328
325
spread = 100
329
326
X = rng .rand (n_samples , n_features ).astype (dtype ) * spread
330
327
Y = rng .rand (n_samples , n_features ).astype (dtype ) * spread
@@ -347,7 +344,9 @@ def test_strategies_consistency(
347
344
parameter ,
348
345
metric = metric ,
349
346
# Taking the first
350
- metric_kwargs = _get_metric_params_list (metric , n_features )[0 ],
347
+ metric_kwargs = _get_metric_params_list (
348
+ metric , n_features , seed = global_random_seed
349
+ )[0 ],
351
350
# To be sure to use parallelization
352
351
chunk_size = n_samples // 4 ,
353
352
strategy = "parallel_on_X" ,
@@ -360,7 +359,9 @@ def test_strategies_consistency(
360
359
parameter ,
361
360
metric = metric ,
362
361
# Taking the first
363
- metric_kwargs = _get_metric_params_list (metric , n_features )[0 ],
362
+ metric_kwargs = _get_metric_params_list (
363
+ metric , n_features , seed = global_random_seed
364
+ )[0 ],
364
365
# To be sure to use parallelization
365
366
chunk_size = n_samples // 4 ,
366
367
strategy = "parallel_on_Y" ,
@@ -384,6 +385,7 @@ def test_strategies_consistency(
384
385
@pytest .mark .parametrize ("metric" , CDIST_PAIRWISE_DISTANCES_REDUCTION_COMMON_METRICS )
385
386
@pytest .mark .parametrize ("strategy" , ("parallel_on_X" , "parallel_on_Y" ))
386
387
def test_pairwise_distances_argkmin (
388
+ global_random_seed ,
387
389
n_features ,
388
390
translation ,
389
391
metric ,
@@ -392,7 +394,7 @@ def test_pairwise_distances_argkmin(
392
394
k = 10 ,
393
395
dtype = np .float64 ,
394
396
):
395
- rng = np .random .RandomState (0 )
397
+ rng = np .random .RandomState (global_random_seed )
396
398
spread = 1000
397
399
X = translation + rng .rand (n_samples , n_features ).astype (dtype ) * spread
398
400
Y = translation + rng .rand (n_samples , n_features ).astype (dtype ) * spread
@@ -443,20 +445,23 @@ def test_pairwise_distances_argkmin(
443
445
@pytest .mark .parametrize ("metric" , CDIST_PAIRWISE_DISTANCES_REDUCTION_COMMON_METRICS )
444
446
@pytest .mark .parametrize ("strategy" , ("parallel_on_X" , "parallel_on_Y" ))
445
447
def test_pairwise_distances_radius_neighbors (
448
+ global_random_seed ,
446
449
n_features ,
447
450
translation ,
448
451
metric ,
449
452
strategy ,
450
453
n_samples = 100 ,
451
454
dtype = np .float64 ,
452
455
):
453
- rng = np .random .RandomState (0 )
456
+ rng = np .random .RandomState (global_random_seed )
454
457
spread = 1000
455
458
radius = spread * np .log (n_features )
456
459
X = translation + rng .rand (n_samples , n_features ).astype (dtype ) * spread
457
460
Y = translation + rng .rand (n_samples , n_features ).astype (dtype ) * spread
458
461
459
- metric_kwargs = _get_metric_params_list (metric , n_features )[0 ]
462
+ metric_kwargs = _get_metric_params_list (
463
+ metric , n_features , seed = global_random_seed
464
+ )[0 ]
460
465
461
466
# Reference for argkmin results
462
467
if metric == "euclidean" :
@@ -500,18 +505,17 @@ def test_pairwise_distances_radius_neighbors(
500
505
)
501
506
502
507
503
- @pytest .mark .parametrize ("seed" , range (10 ))
504
508
@pytest .mark .parametrize ("n_samples" , [100 , 1000 ])
505
509
@pytest .mark .parametrize ("n_features" , [5 , 10 , 100 ])
506
510
@pytest .mark .parametrize ("num_threads" , [1 , 2 , 8 ])
507
511
def test_sqeuclidean_row_norms (
508
- seed ,
512
+ global_random_seed ,
509
513
n_samples ,
510
514
n_features ,
511
515
num_threads ,
512
516
dtype = np .float64 ,
513
517
):
514
- rng = np .random .RandomState (seed )
518
+ rng = np .random .RandomState (global_random_seed )
515
519
spread = 100
516
520
X = rng .rand (n_samples , n_features ).astype (dtype ) * spread
517
521
0 commit comments