Skip to content

svd stuck in infinite loop for certain matrices #81

@cvsvensson

Description

@cvsvensson

Using svd on certain matrices leads to an infinite loop:

using LinearAlgebra, GenericLinearAlgebra
m = [1 0 0 0; 0 2 1 0; 0 1 2 0; 0 0 0 -1]
svd(m) # ok
svd(BigFloat.(m)) # stuck in infinite loop
svdvals!(Float64.(m), debug=true) # also stuck, so it's not BigFloat's fault.

The svd of some permutations of the matrix works:

perm = [2,3,1,4]
svd(BigFloat.(m[perm,perm])) # ok

For this particular matrix, any small perturbation (e.g. m + 1e-10*rand(4,4)) seem to work fine but there are other matrices, such as

m2 = [0.4 0 0 0 0 0 0 0; 0 0.8 0 0 0 0 1 0; 0 0 -0.3 0 0 0 0 0; 0 0 0 -0.4 0 0 0 0; 0 0 0 0 0.4 0 0 0; 0 0 0 0 0 -0.3 0 0; 0 1 0 0 0 0 0.8 0; 0 0 0 0 0 0 0 -0.4]

where svdvals!(m2+1e-2*rand(8,8), debug=true) often gets stuck.

The problem may be related to the code linked below. If I replace shift^2 < eps(B.dv[n1]^2) with true, the infinite loop is avoided, but I don't know if this is a proper thing to do.

shift = svdvals2x2(d[n2 - 1], d[n2], e[n2 - 1])[1]
if shift^2 < eps(B.dv[n1]^2)
# Shift is too small to affect the iteration so just use
# zero-shift algorithm anyway
svdDemmelKahan!(B, n1, n2, U, Vᴴ)
else
svdIter!(B, n1, n2, shift, U, Vᴴ)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions