Skip to content

Add retrying normalization if necessary. #39

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ version = "0.4.3"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[compat]
Adapt = "2.1, 3.0"
Expand Down
16 changes: 16 additions & 0 deletions src/svd.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using KrylovKit
using Random: rand!
function _biLanczosIterations!(A, stepsize, αs, βs, U, V, μs, νs, maxνs, maxμs, τ, reorth_in, tolreorth, debug)

m, n = size(A)
Expand Down Expand Up @@ -50,6 +52,20 @@ function _biLanczosIterations!(A, stepsize, αs, βs, U, V, μs, νs, maxνs, ma
nReorthVecs += 1
end
α = norm(v)

if α < τ * maximum(size(A)) * eps() # orthogonalization failed, see https://github.com/poulson/PROPACK/blob/2465f89d5b1fba56de71c3e69e27d017c3dc2295/double/dlanbpro.F#L384
debug && println("Restart orthogonalization")
b = V[1:(j-1)]
B = KrylovKit.OrthonormalBasis(b ./ norm.(b))
for _ in 1:3
v = rand!(v) * 2 .- 1
KrylovKit.orthonormalize!(v, B, KrylovKit.ModifiedGramSchmidt())
α = norm(v)
if !(α < τ * maximum(size(A)) * eps())
break
end
end
end
end

## update the result vectors
Expand Down