Issues with pairwise_distances(metric='euclidean') when used on the output of UMAP

### Describe the bug

When using pairwise_distances with metric='euclidean' on the output of some data from a UMAP, a `RuntimeWarning: divide by zero encountered in matmul ret = a @ b` is raised. This warning is not raised if you just use pairwise_distances on some normally distributed values of the same dimension, it specifically happens when used on the output of UMAP. The warning is not raised if calling `scipy.pdist` on the same data. The warning doesn't come up with any other metric (other than euclidean family e.g. nan_euclidean etc)

### Steps/Code to Reproduce

```python
import numpy as np
import umap.umap_ as umap 
from sklearn.metrics import pairwise_distances

np.random.seed(42)
arr = np.random.normal(size = (300, 10))
reducer = umap.UMAP()
embedding = reducer.fit_transform(arr)

# this line produces the warning 
dist_mat = pairwise_distances(embedding, metric = 'euclidean')

# no warning produced by this code
synthetic = np.random.normal(size = (300, 2))
dist_mat_synth = pairwise_distances(synthetic, metric = 'euclidean')
```

### Expected Results

Would expect to see no RuntimeWarning (FutureWarning is expected)

### Actual Results

``` 

[.../site-packages/sklearn/utils/deprecation.py:151]: FutureWarning: 'force_all_finite' was renamed to 'ensure_all_finite' in 1.6 and will be removed in 1.8.
  warnings.warn(
[.../site-packages/sklearn/utils/extmath.py:203] RuntimeWarning: divide by zero encountered in matmul
  ret = a @ b
[.../site-packages/sklearn/utils/extmath.py:203]: RuntimeWarning: overflow encountered in matmul
  ret = a @ b
[.../site-packages/sklearn/utils/extmath.py:203]: RuntimeWarning: invalid value encountered in matmul
  ret = a @ b

```

### Versions

```shell
System:
    python: 3.10.16 (main, Feb 25 2025, 09:29:51) [Clang 16.0.0 (clang-1600.0.26.6)]
executable: .../bin/python
   machine: macOS-15.4-arm64-arm-64bit

Python dependencies:
      sklearn: 1.6.1
          pip: 25.0.1
   setuptools: 65.5.0
        numpy: 2.1.3
        scipy: 1.15.1
       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: 14
         prefix: libomp
       filepath: .../site-packages/sklearn/.dylibs/libomp.dylib
        version: None

       user_api: openmp
   internal_api: openmp
    num_threads: 14
         prefix: libomp
       filepath: /opt/homebrew/Cellar/libomp/19.1.7/lib/libomp.dylib
        version: None
```

COMMENT:
I also ran some tests with different input scenarios and did not encounter any RuntimeWarning. Here are the test types and the code used:

```
import numpy as np
import umap
from sklearn.metrics import pairwise_distances

def test_pairwise_distances(data, label):
    reducer = umap.UMAP()
    embedding = reducer.fit_transform(data)
    print(f"=== [{label}] ===")
    print(f"Embedding shape: {embedding.shape}")
    dist_mat = pairwise_distances(embedding, metric='euclidean')
    print(f"Distance matrix: min={np.min(dist_mat)}, max={np.max(dist_mat)}")

# Tests with different types of data
np.random.seed(42)

# Normal random input
arr = np.random.normal(size=(300, 10))
test_pairwise_distances(arr, "Normal Random")

# Tiny uniform noise
tiny_uniform = np.random.uniform(low=-1e-5, high=1e-5, size=(300, 10))
test_pairwise_distances(tiny_uniform, "Tiny Uniform Noise")

# Constant data
constant_data = np.full((300, 10), 1.0)
test_pairwise_distances(constant_data, "Constant")

# Near-constant data
near_constant_data = np.full((300, 10), 1.0) + np.random.normal(scale=1e-5, size=(300, 10))
test_pairwise_distances(near_constant_data, "Near-Constant")

# Float16 precision
float16_data = np.random.normal(size=(300, 10)).astype(np.float16)
test_pairwise_distances(float16_data, "Float16 Precision")

# Dense clusters (e.g., small clusters of data)
dense_clusters = np.vstack([np.random.normal(loc=0.0, scale=0.1, size=(100, 10)),
                            np.random.normal(loc=1.0, scale=0.1, size=(100, 10)),
                            np.random.normal(loc=2.0, scale=0.1, size=(100, 10))])
test_pairwise_distances(dense_clusters, "Dense Clusters")
```


For all tests, the UMAP embedding shape was (300, 2), and pairwise_distances(..., metric='euclidean') ran without warnings. The distance matrix values were valid and within expected ranges.

I'm not sure but the issue could be environment specific ?? Let me know if I can help further

Labels: Bug, Needs Investigation