File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,13 @@ Version 1.0.2
12
12
Changelog
13
13
---------
14
14
15
+ :mod: `sklearn.cluster `
16
+ ......................
17
+
18
+ - |Fix | Fixed an infinite loop in :func: `cluster.SpectralClustering ` by
19
+ moving an iteration counter from try to except.
20
+ :pr: `21271 ` by :user: `Tyler Martin <martintb> `
21
+
15
22
:mod: `sklearn.decomposition `
16
23
............................
17
24
@@ -28,7 +35,6 @@ Changelog
28
35
descriptions in the generated HTML. :pr: `21493 ` by
29
36
:user: `Aurélien Geron <ageron> `.
30
37
31
-
32
38
.. _changes_1_0_1 :
33
39
34
40
Version 1.0.1
Original file line number Diff line number Diff line change @@ -172,8 +172,8 @@ def discretize(
172
172
173
173
try :
174
174
U , S , Vh = np .linalg .svd (t_svd )
175
- svd_restarts += 1
176
175
except LinAlgError :
176
+ svd_restarts += 1
177
177
print ("SVD did not converge, randomizing and trying again" )
178
178
break
179
179
Original file line number Diff line number Diff line change 3
3
4
4
import numpy as np
5
5
from scipy import sparse
6
+ from scipy .linalg import LinAlgError
6
7
7
8
import pytest
8
9
@@ -354,3 +355,19 @@ def test_spectral_clustering_np_matrix_raises():
354
355
msg = r"spectral_clustering does not support passing in affinity as an np\.matrix"
355
356
with pytest .raises (TypeError , match = msg ):
356
357
spectral_clustering (X )
358
+
359
+
360
+ def test_spectral_clustering_not_infinite_loop (capsys , monkeypatch ):
361
+ """Check that discretize raises LinAlgError when svd never converges.
362
+
363
+ Non-regression test for #21380
364
+ """
365
+
366
+ def new_svd (* args , ** kwargs ):
367
+ raise LinAlgError ()
368
+
369
+ monkeypatch .setattr (np .linalg , "svd" , new_svd )
370
+ vectors = np .ones ((10 , 4 ))
371
+
372
+ with pytest .raises (LinAlgError , match = "SVD did not converge" ):
373
+ discretize (vectors )
You can’t perform that action at this time.
0 commit comments