Skip to content

Commit 1c8214b

Browse files
committed
Fix convergence criterion such that we don't try to be smart to save
the computation of the vectors. Update REQUIRE for julia 0.7
1 parent f90ad3d commit 1c8214b

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

REQUIRE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
julia 0.7-beta
1+
julia 0.7

src/svd.jl

+12-18
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,6 @@ function _tsvd(A,
169169
# Save the estimates of the maximum angles between Lanczos vectors
170170
append!(maxμs, maxμ)
171171

172-
# vals0 = svdvals(Bidiagonal(αs, βs[1:end-1], :L))
173-
vals0 = svdvals(Bidiagonal([αs;z], βs, :L))
174-
vals1 = vals0
175-
176172
hasConv = false
177173
while iter <= maxiter
178174
_tmp, _tmp, _tmp, _tmp, _tmp, _tmp, reorth_μ, maxμ, maxν, _tmp =
@@ -181,23 +177,21 @@ function _tsvd(A,
181177
append!(maxνs, maxν)
182178
iter += stepsize
183179

184-
# vals1 = svdvals(Bidiagonal(αs, βs[1:end-1], :L))
185-
vals1 = svdvals(Bidiagonal([αs;z], βs, :L))
180+
# This is more expensive than necessary because we only need the last components. However, LAPACK doesn't support this.
181+
UU, ss, VV = svd(Bidiagonal([αs;z], βs, :L))
186182

187-
debug && @show vals1[nvals]/vals0[nvals] - 1
183+
debug && @show βs[end]
188184

189-
if vals0[nvals]*(1 - tolconv) < vals1[nvals] < vals0[nvals]*(1 + tolconv)
190-
# UU, ss, VV = svd(Bidiagonal([αs;z], βs[1:end-1], :L))
191-
# This is more expensive than necessary because we only need the last components. However, LAPACK doesn't support this.
192-
UU, ss, VV = svd(Bidiagonal([αs;z], βs, :L))
193-
# @show UU[end, 1:iter]*βs[end]
194-
if all(abs.(UU[end, 1:nvals])*βs[end] .< tolconv*ss[1:nvals]) && all(abs.(VV[end, 1:nvals])*βs[end] .< tolconv*ss[1:nvals])
195-
hasConv = true
196-
break
197-
end
185+
# Test for convergence. A Ritzvalue is considered converged if
186+
# either the last component of the corresponding vector is (relatively)
187+
# small or if the last component in βs is small (or both)
188+
if all(abs.(UU[end, 1:nvals])*βs[end] .< tolconv*ss[1:nvals]) &&
189+
all(abs.(VV[end, 1:nvals])*βs[end] .< tolconv*ss[1:nvals])
190+
hasConv = true
191+
break
198192
end
199-
vals0 = vals1
200-
τ = eps(eltype(vals1))*vals1[1]
193+
194+
τ = eps(eltype(ss))*ss[1]
201195

202196
debug && @show iter
203197
debug && @show τ

test/runtests.jl

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
using Test, TSVD, LinearAlgebra, SparseArrays
22

3-
@testset "test tsvd with m = $m, n = $n, and p = $p" for (m, n, p) = ((10, 6, 0.8), (100, 60, 0.1))
3+
@testset "test tsvd with m = $m, n = $n, and p = $p" for
4+
(m, n, p) in ((10, 6, 0.8),
5+
(6, 10, 0.8),
6+
(10, 10, 0.8),
7+
(100, 60, 0.1),
8+
(60, 100, 0.1),
9+
(100, 100, 0.1))
10+
411
mnp = round(Integer, m*n*p)
512

613
for A in (randn(m, n),

0 commit comments

Comments
 (0)