Fix low level crash in BisectingKMeans.predict on rescaled data - #27167
Conversation
|
Victory! The non-regression test is actually causing a crash on the macOS intel CI as expected: Current thread 0x0000000107bdae00 (most recent call first):
File "/Users/runner/work/1/s/sklearn/cluster/_kmeans.py", line 796 in _labels_inertia
File "/Users/runner/work/1/s/sklearn/cluster/_kmeans.py", line 820 in _labels_inertia_threadpool_limit
File "/Users/runner/work/1/s/sklearn/cluster/_bisect_k_means.py", line 504 in _predict_recursive
File "/Users/runner/work/1/s/sklearn/cluster/_bisect_k_means.py", line 520 in _predict_recursive
File "/Users/runner/work/1/s/sklearn/cluster/_bisect_k_means.py", line 471 in predict
File "/Users/runner/work/1/s/sklearn/cluster/tests/test_bisect_k_means.py", line 148 in test_non_regression_segfault_on_empty_bisectionsLet's now check that the fix works as expected. |
|
Note: this PR implements the fix both in the Python caller and the Cython callee:
In theory, only one of those two fixes is actually needed, but I am not sure where it's best to fix this bug so I decided to fix it at both locations. EDIT: I changed my mind and decided to make to make it explicit in the Cython code that it's expected to call the no-op case. This makes the Python code of bisecting k-means simpler as a result. |
|
The tests pass! I will generalize the fix to Elkan next week as suggested by @jjerphan. Have a nice WE. |
|
In the end I decided to only keep the Cython side of the fix for the sake of simplicity. I updated the comments accordingly. |
OmarManzoor
left a comment
There was a problem hiding this comment.
LGTM. Thanks @ogrisel
Fixes #27081.
I will first open this PR with the non-regression test that should hopefully make the macOS Intel CI workers segfault (for some reason, this bug seems to stay silent on other platforms)...
Then I will push a fix for the underlying root cause.