@@ -395,7 +395,8 @@ def test_empirical_covariance_array_api(
395395 X_np = X .astype (dtype_name , copy = False )
396396 X_xp = xp .asarray (X_np , device = device )
397397
398- result_np = empirical_covariance (X_np , assume_centered = assume_centered )
398+ with config_context (array_api_dispatch = False ):
399+ result_np = empirical_covariance (X_np , assume_centered = assume_centered )
399400
400401 with config_context (array_api_dispatch = True ):
401402 result_xp = empirical_covariance (X_xp , assume_centered = assume_centered )
@@ -418,7 +419,8 @@ def test_ledoit_wolf_shrinkage_array_api(
418419 X_np = X [:, :n_features ].astype (dtype_name , copy = False )
419420 X_xp = xp .asarray (X_np , device = device )
420421
421- shrinkage_np = ledoit_wolf_shrinkage (X_np )
422+ with config_context (array_api_dispatch = False ):
423+ shrinkage_np = ledoit_wolf_shrinkage (X_np )
422424
423425 with config_context (array_api_dispatch = True ):
424426 shrinkage_xp = ledoit_wolf_shrinkage (X_xp )
@@ -436,10 +438,11 @@ def test_log_likelihood_array_api(array_namespace, device_name, dtype_name):
436438 xp , device = _array_api_for_tests (array_namespace , device_name , dtype_name )
437439
438440 X_np = X .astype (dtype_name , copy = False )
439- emp_cov_np = empirical_covariance (X_np )
440- est = EmpiricalCovariance ().fit (X_np )
441- precision_np = est .get_precision ()
442- result_np = log_likelihood (emp_cov_np , precision_np )
441+ with config_context (array_api_dispatch = False ):
442+ emp_cov_np = empirical_covariance (X_np )
443+ est = EmpiricalCovariance ().fit (X_np )
444+ precision_np = est .get_precision ()
445+ result_np = log_likelihood (emp_cov_np , precision_np )
443446
444447 # Downcast to target dtype before converting because `empirical_covariance` can
445448 # return float64 for numpy and MPS only supports float32
@@ -469,8 +472,9 @@ def test_score_array_api(array_namespace, device_name, dtype_name, store_precisi
469472 lw_xp = LedoitWolf (store_precision = store_precision ).fit (X_xp )
470473 score_xp = lw_xp .score (X_xp )
471474
472- lw_np = LedoitWolf (store_precision = store_precision ).fit (X_np )
473- score_np = lw_np .score (X_np )
475+ with config_context (array_api_dispatch = False ):
476+ lw_np = LedoitWolf (store_precision = store_precision ).fit (X_np )
477+ score_np = lw_np .score (X_np )
474478
475479 assert isinstance (score_xp , float )
476480 assert_allclose (score_np , score_xp , atol = _atol_for_type (dtype_name ))
@@ -488,8 +492,9 @@ def test_error_norm_array_api(array_namespace, device_name, dtype_name, norm):
488492 X_np = X .astype (dtype_name , copy = False )
489493 X_xp = xp .asarray (X_np , device = device )
490494
491- lw_np = LedoitWolf ().fit (X_np )
492- comp_cov_np = empirical_covariance (X_np )
495+ with config_context (array_api_dispatch = False ):
496+ lw_np = LedoitWolf ().fit (X_np )
497+ comp_cov_np = empirical_covariance (X_np )
493498
494499 with config_context (array_api_dispatch = True ):
495500 lw_xp = LedoitWolf ().fit (X_xp )
@@ -498,7 +503,8 @@ def test_error_norm_array_api(array_namespace, device_name, dtype_name, norm):
498503 comp_cov_xp = xp .asarray (comp_cov_np .astype (dtype_name ), device = device )
499504 result_xp = lw_xp .error_norm (comp_cov_xp , norm = norm )
500505
501- result_np = lw_np .error_norm (comp_cov_np , norm = norm )
506+ with config_context (array_api_dispatch = False ):
507+ result_np = lw_np .error_norm (comp_cov_np , norm = norm )
502508 assert_allclose (result_np , float (result_xp ), atol = _atol_for_type (dtype_name ))
503509
504510
@@ -513,8 +519,9 @@ def test_mahalanobis_array_api(array_namespace, device_name, dtype_name):
513519 X_np = X .astype (dtype_name , copy = False )
514520 X_xp = xp .asarray (X_np , device = device )
515521
516- lw_np = LedoitWolf ().fit (X_np )
517- dist_np = lw_np .mahalanobis (X_np )
522+ with config_context (array_api_dispatch = False ):
523+ lw_np = LedoitWolf ().fit (X_np )
524+ dist_np = lw_np .mahalanobis (X_np )
518525
519526 with config_context (array_api_dispatch = True ):
520527 lw_xp = LedoitWolf ().fit (X_xp )
0 commit comments