@@ -1124,16 +1124,18 @@ def test_dtype_match_cholesky():
1124
1124
1125
1125
@pytest .mark .parametrize (
1126
1126
'solver' , ['svd' , 'cholesky' , 'lsqr' , 'sparse_cg' , 'sag' , 'saga' ])
1127
- def test_ridge_regression_dtype_stability (solver ):
1128
- random_state = np .random .RandomState (0 )
1127
+ @pytest .mark .parametrize ('seed' , range (1 ))
1128
+ def test_ridge_regression_dtype_stability (solver , seed ):
1129
+ random_state = np .random .RandomState (seed )
1129
1130
n_samples , n_features = 6 , 5
1130
1131
X = random_state .randn (n_samples , n_features )
1131
1132
coef = random_state .randn (n_features )
1132
- y = np .dot (X , coef ) + 0.01 * rng .randn (n_samples )
1133
+ y = np .dot (X , coef ) + 0.01 * random_state .randn (n_samples )
1133
1134
alpha = 1.0
1134
- rtol = 1e-2 if os .name == 'nt' and _IS_32BIT else 1e-5
1135
-
1136
1135
results = dict ()
1136
+ # XXX: Sparse CG seems to be far less numerically stable than the
1137
+ # others, maybe we should not enable float32 for this one.
1138
+ atol = 1e-3 if solver == "sparse_cg" else 1e-5
1137
1139
for current_dtype in (np .float32 , np .float64 ):
1138
1140
results [current_dtype ] = ridge_regression (X .astype (current_dtype ),
1139
1141
y .astype (current_dtype ),
@@ -1148,4 +1150,4 @@ def test_ridge_regression_dtype_stability(solver):
1148
1150
1149
1151
assert results [np .float32 ].dtype == np .float32
1150
1152
assert results [np .float64 ].dtype == np .float64
1151
- assert_allclose (results [np .float32 ], results [np .float64 ], rtol = rtol )
1153
+ assert_allclose (results [np .float32 ], results [np .float64 ], atol = atol )
0 commit comments