Skip to content

randomized_svd incorrect for complex valued matrices #30736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
clane9 opened this issue Jan 30, 2025 · 0 comments · Fixed by #30819
Closed

randomized_svd incorrect for complex valued matrices #30736

clane9 opened this issue Jan 30, 2025 · 0 comments · Fixed by #30819
Labels

Comments

@clane9
Copy link
Contributor

clane9 commented Jan 30, 2025

Describe the bug

The randomized_svd utility function accepts complex valued inputs without error, but the result is inconsistent with scipy.linalg.svd.

Steps/Code to Reproduce

import numpy as np
from scipy import linalg
from sklearn.utils.extmath import randomized_svd

rng = np.random.RandomState(42)
X = rng.randn(100, 20) + 1j * rng.randn(100, 20)

_, s, _ = linalg.svd(X)
_, s2, _ = randomized_svd(X, n_components=5)

print("s:", s[:5])
print("s2:", s2[:5])

Expected Results

I expected the singular values to be numerically close.

Actual Results

s: [19.81481515 18.69019042 17.62107998 17.23689681 16.3148512 ]
s2: [11.25690754  9.97157079  9.01542947  8.06160863  7.54068744]

Versions

System:
    python: 3.11.4 (main, Jul  5 2023, 08:40:20) [Clang 14.0.6 ]
executable: /Users/clane/miniconda3/bin/python
   machine: macOS-13.7-arm64-arm-64bit

Python dependencies:
      sklearn: 1.7.dev0
          pip: 25.0
   setuptools: 65.5.0
        numpy: 2.2.2
        scipy: 1.15.1
       Cython: 3.0.11
       pandas: 2.2.3
   matplotlib: 3.10.0
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 8
         prefix: libscipy_openblas
       filepath: /Users/clane/Projects/misc/scikit-learn/.venv/lib/python3.11/site-packages/numpy/.dylibs/libscipy_openblas64_.dylib
        version: 0.3.28
threading_layer: pthreads
   architecture: neoversen1

       user_api: blas
   internal_api: openblas
    num_threads: 8
         prefix: libscipy_openblas
       filepath: /Users/clane/Projects/misc/scikit-learn/.venv/lib/python3.11/site-packages/scipy/.dylibs/libscipy_openblas.dylib
        version: 0.3.28
threading_layer: pthreads
   architecture: neoversen1

       user_api: openmp
   internal_api: openmp
    num_threads: 8
         prefix: libomp
       filepath: /opt/homebrew/Cellar/libomp/19.1.3/lib/libomp.dylib
        version: None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants