Skip to content

Commit

Permalink
Merge pull request #26 from JuliaLinearAlgebra/an/degenerate
Browse files Browse the repository at this point in the history
Add a slight perturbation to initial α if it is one so ensure that
  • Loading branch information
andreasnoack authored Nov 5, 2020
2 parents 6d31728 + c32d478 commit 018b7f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function _biLanczosIterations!(A, stepsize, αs, βs, U, V, μs, νs, maxνs, ma
β = βs[iter]

for j = iter .+ (1:stepsize)

# The v step
vOld = v
## apply operator
Expand Down Expand Up @@ -127,6 +126,11 @@ function biLanczos(A,
v = A'initvec
rmul!(v, inv(nrmInit))
α = norm(v)
if isone(α)
# We need v to change when scaled with α.
# Otherwise the basis generation might break down.
α = nextfloat(α)
end
rmul!(v, inv(α))
V = fill(v, 1)
αs = fill(α, 1)
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ end
data = rand(1:100, 50, 50)
@test @inferred(TSVD.tsvd(data, 2))[2] svdvals(data)[1:2]
end

@testset "Issue 25. Degenerate basis" begin
@test tsvd([1 0 ; 0 1], 1, initvec=[1.0; 0.0])[2] [1.0]
end

0 comments on commit 018b7f8

Please sign in to comment.