You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
np.linalg.matrix_rank calculates the rank of the matrix and gives the wrong result #19473
When I use the numpy function(np.linalg.matrix_rank) to calculate the rank of the matrix, the function returns the rank of the matrix as 0, and then when I use matlab to calculate the rank of the same matrix, matlab got the correct result(30). I compared numpy and matlab calculations The source code of the matrix rank, but there seems to be no difference between the two ways.
Sometimes, numpy will prompt RuntimeWarning
How should i solve this problem?
The inf in the compute_uv=False case upsets the default tolerance calculation, hence the calculated rank of 0.
For background, the mat array is an array containing 0s and 1s, of shape (98, 98) where 22 columns have a single 1 somewhere, and 8 columns have two 1s.
Further investigation: the np.linalg.svd(mat, compute_uv=False) variant, but not the compute_uv=True variant, produces a np.inf and 5 np.nan singular values, and only for export OPENBLAS_CORETYPE=haswell . I haven't tested on other BLAS libraries.
Activity
matthew-brett commentedon Jul 14, 2021
Interesting - this boils down to:
The
infin thecompute_uv=Falsecase upsets the default tolerance calculation, hence the calculated rank of 0.For background, the
matarray is an array containing 0s and 1s, of shape (98, 98) where 22 columns have a single 1 somewhere, and 8 columns have two 1s.matthew-brett commentedon Jul 16, 2021
Further investigation: the
np.linalg.svd(mat, compute_uv=False)variant, but not thecompute_uv=Truevariant, produces anp.infand 5np.nansingular values, and only forexport OPENBLAS_CORETYPE=haswell. I haven't tested on other BLAS libraries.matthew-brett commentedon Jul 16, 2021
OpenBLAS bug report : OpenMathLib/OpenBLAS#3318
Dinkarkumar commentedon Aug 21, 2021
is the issue resolved ?
matthew-brett commentedon Aug 21, 2021
No, not resolved yet. We need an OpenBLAS build that includes OpenMathLib/OpenBLAS#3320 .
I've just tested with the latest wheel, using:
I've attached the test files in the zip archive, but the test boils down to:
Where
svd_check.pyis:When the bug is still present, you will see:
svd_check.zip