RuntimeWarnings: divide by zero, overflow, invalid value encountered in matmul

### Describe the bug

While running feature selection, I get the following warnings:
.../lib/python3.12/site-packages/sklearn/utils/extmath.py:203: RuntimeWarning: divide by zero encountered in matmul
  ret = a @ b
.../lib/python3.12/site-packages/sklearn/utils/extmath.py:203: RuntimeWarning: overflow encountered in matmul
  ret = a @ b
.../lib/python3.12/site-packages/sklearn/utils/extmath.py:203: RuntimeWarning: invalid value encountered in matmul
 ret = a @ b



### Steps/Code to Reproduce

from sklearn.datasets import make_friedman1
from sklearn.feature_selection import RFECV
from sklearn.svm import SVR
X, y = make_friedman1(n_samples=500, n_features=100, random_state=0)
estimator = SVR(kernel="linear")
selector = RFECV(estimator, step=1, cv=5)
selector = selector.fit(X, y)
print(selector.support_)

### Expected Results

[ True  True False  True  True False False False False False False False
 False False False False False False False False False False False False
 False False False False False False False False False False False False
 False False False False False False False False False False False False
 False False False False False False False False False False False False
 False False False False False False False False False False False False
 False False False False False False False False False False False False
 False False False False False False False False False False False False
 False False False False]

### Actual Results

.../lib/python3.12/site-packages/sklearn/utils/extmath.py:203: RuntimeWarning: divide by zero encountered in matmul
  ret = a @ b
.../lib/python3.12/site-packages/sklearn/utils/extmath.py:203: RuntimeWarning: overflow encountered in matmul
  ret = a @ b
.../lib/python3.12/site-packages/sklearn/utils/extmath.py:203: RuntimeWarning: invalid value encountered in matmul
  ret = a @ b
...
[ True  True False  True  True False False False False False False False
 False False False False False False False False False False False False
 False False False False False False False False False False False False
 False False False False False False False False False False False False
 False False False False False False False False False False False False
 False False False False False False False False False False False False
 False False False False False False False False False False False False
 False False False False False False False False False False False False
 False False False False]

### Versions

```shell
System:
    python: 3.12.8 (v3.12.8:2dc476bcb91, Dec  3 2024, 14:43:19) [Clang 13.0.0 (clang-1300.0.29.30)]
executable: /Users/******/PyEnvs/JAN2025/bin/python
   machine: macOS-15.5-arm64-arm-64bit

Python dependencies:
      sklearn: 1.6.1
          pip: 25.1.1
   setuptools: 75.8.0
        numpy: 2.2.5
        scipy: 1.15.0
       Cython: None
       pandas: 2.2.3
   matplotlib: 3.10.0
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
    num_threads: 10
         prefix: libomp
       filepath: /Users/******/PyEnvs/JAN2025/lib/python3.12/site-packages/sklearn/.dylibs/libomp.dylib
        version: None
```

COMMENT:
Yes, the problem arises on macOS M4.  Thanks

> On May 20, 2025, at 00:41, Loïc Estève ***@***.***> wrote:
> 
> 
> lesteve
>  left a comment 
> (scikit-learn/scikit-learn#31395)
>  <https://github.com/scikit-learn/scikit-learn/issues/31395#issuecomment-2893296638>
> I can not reproduce the behaviour on a Linux machine.
> 
> Do you happen to have a macOS M4, if yes it could be linked numpy/numpy#28687 <https://github.com/numpy/numpy/issues/28687>,
> 
> I am going to close this issue, because it is likely to be an issue in numpy rather than scikit-learn. Fee free to reopen if there is a clear indication that the problem is related to scikit-learn.
> 
> —
> Reply to this email directly, view it on GitHub <https://github.com/scikit-learn/scikit-learn/issues/31395#issuecomment-2893296638>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/A4JSO54BIZEP5OV2PK4PEGD27LMCVAVCNFSM6AAAAAB5OMODAKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQOJTGI4TMNRTHA>.
> You are receiving this because you authored the thread.
>

Labels: Bug, Needs Triage