Skip to content
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

ValueError: On entry to SGESDD parameter number 12 had an illegal value #5401

Closed
ppalasek opened this issue Oct 21, 2015 · 9 comments
Closed
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.linalg

Comments

@ppalasek
Copy link

Hello,

I'm getting a ValueError from scipy/linalg/decomp_svd.py, line 104 when tring to run sklearn's pca.fit() function.

Traceback:
File "train.py", line 269, in
pca.fit(X)
File "/homes/pp305/.local/lib/python2.7/site-packages/sklearn/decomposition/pca.py", line 221, in fit
self._fit(X)
File "/homes/pp305/.local/lib/python2.7/site-packages/sklearn/decomposition/pca.py", line 271, in _fit
U, S, V = linalg.svd(X, full_matrices=False)
File "/homes/pp305/.local/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 104, in svd
full_matrices=full_matrices, overwrite_a=overwrite_a)
ValueError: On entry to SGESDD parameter number 12 had an illegal value

Versions I'm using:
Python 2.7.5
scipy 0.16.0
sklearn 0.16.1
numpy 1.9.2

print scipy.config.show()
atlas_3_10_blas_threads_info:
libraries = ['tatlas']
library_dirs = ['/usr/lib64/atlas']
define_macros = [('HAVE_CBLAS', None), ('ATLAS_INFO', '""3.10.1""')]
language = c
include_dirs = ['/usr/include']
lapack_opt_info:
libraries = ['tatlas', 'tatlas', 'tatlas']
library_dirs = ['/usr/lib64/atlas']
define_macros = [('ATLAS_INFO', '""3.10.1""')]
language = f77
include_dirs = ['/usr/include']
blas_opt_info:
libraries = ['tatlas']
library_dirs = ['/usr/lib64/atlas']
define_macros = [('HAVE_CBLAS', None), ('ATLAS_INFO', '""3.10.1""')]
language = c
include_dirs = ['/usr/include']
openblas_info:
NOT AVAILABLE
openblas_lapack_info:
NOT AVAILABLE
atlas_3_10_threads_info:
libraries = ['tatlas', 'tatlas', 'tatlas']
library_dirs = ['/usr/lib64/atlas']
define_macros = [('ATLAS_INFO', '""3.10.1""')]
language = f77
include_dirs = ['/usr/include']
lapack_mkl_info:
NOT AVAILABLE
blas_mkl_info:
NOT AVAILABLE
mkl_info:
NOT AVAILABLE
None

I found an issue like this here already:
#3895

Could you let me know how I can go about getting this to work?

Thank you!

@pv
Copy link
Member

pv commented Oct 21, 2015 via email

@ppalasek
Copy link
Author

Hello,

LAPACK version is 3.4.2 and the size of the matrix was 9537x46080.

Now I tried using matrices with other dimensions and I'm getting the same error when I try with matrices of sizes 9537x20000, 9537x10000, 9537x9538, 9537x9537.

If I use a matrix of size 9537x9536 it's working fine.

@pv
Copy link
Member

pv commented Oct 21, 2015

LAPACK uses 32-bit integers and will start failing if the work space size becomes larger than INT_MAX. You can maybe check this via

import numpy as np
from scipy.linalg import lapack
intmax = np.iinfo(np.intc).max
n, m = 9537, 9537
lwork = lapack.sgesdd_lwork(n, n, True, True)[0]
print(lwork / intmax) # should be < 1

# Try to decompose:
a = np.random.rand(n,n)
lapack.sgesdd(a, True, True, lwork=int(lwork))

n=9537 is however not yet so big it should be problematic, at least with lapack 3.5.0, but it is not very far from the limit either. Maybe it is different on 3.4.2?

@ppalasek
Copy link
Author

OK, I ran the code you wrote and got the same error:

python test.py
0.127092868149
Traceback (most recent call last):
File "test.py", line 10, in
lapack.sgesdd(a, True, True, lwork=int(lwork))
ValueError: On entry to SGESDD parameter number 12 had an illegal value

with n = 9536 it works.

What do you suggest? Should I just try upgrading lapack, or is there something else I can try?

Thank you!

@ppalasek
Copy link
Author

Just to update, I tried your code again with n=9538, n=9600 and with n=10000 and it worked each time. I also tried running with n=20000 and n=40000 and it seems to be working both times (I didn't wait until it finished).

n=9537 still resulting in error (). Is there something special about 9537 or lwork being 272929856?

@pv
Copy link
Member

pv commented Oct 21, 2015

These numbers come directly from LAPACK. What I think is happening is the following: LAPACK sgesdd lwork query returns the optimal lwork as a single-precision float value. However, the next possible float32 number bigger than 272929856 is actually 272929888. If the value of lwork LAPACK computed falls between these two, it gets rounded down when returned in a float32 variable and may end up being too small.

So I think:

  • This is a LAPACK bug (should be reproduced with a small fortran program and reported to LAPACK authors).
  • Scipy should work around it, by taking the next largest floating point value (lwork = int(np.nextafter(lwork, np.float32(np.inf))) instead of lwork = int(lwork)).

In the meantime, you can work around it by using the low-level lapack.*gesdd* routines instead of scipy.linalg.svd.

@ppalasek
Copy link
Author

Thank you very much for your replies! I will try to use your workaround.

@pv pv added defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.linalg labels Oct 24, 2015
@pv
Copy link
Member

pv commented Oct 24, 2015

LAPACK bug report: http://icl.cs.utk.edu/lapack-forum/viewtopic.php?f=13&t=4836
Workaround in gh-5413

@pv
Copy link
Member

pv commented Nov 10, 2015

andreasnoack added a commit to JuliaLang/julia that referenced this issue Apr 10, 2016
andreasnoack added a commit to JuliaLang/julia that referenced this issue Apr 10, 2016
andreasnoack added a commit to JuliaLang/julia that referenced this issue Apr 11, 2016
tkelman pushed a commit to JuliaLang/julia that referenced this issue Sep 13, 2016
ararslan pushed a commit to JuliaAttic/Benchmarks that referenced this issue Mar 5, 2018
sgesdd by using nextfloat. Now with comments and test so this commit
supersedes ad59ceb6398114b6ee49756ed14f493d9d28485c

See

http://icl.cs.utk.edu/lapack-forum/viewtopic.php?f=13&t=4587&p=11036&hilit=sgesdd#p11036

and

scipy/scipy#5401

Fixes #15784
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.linalg
Projects
None yet
Development

No branches or pull requests

2 participants