Skip to content

Commit 4c0cdf5

Browse files
author
Pawel Latawiec
committed
Relax singularity check for tolerance
1 parent 011c631 commit 4c0cdf5

File tree

3 files changed

+12
-39
lines changed

3 files changed

+12
-39
lines changed

src/lal.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ mutable struct LookAheadLanczosDecomp{OpT, OptT, VecT, MatT, ElT, ElRT}
106106

107107
# Estimate of norm(A), see [^Freund1993]
108108
nA::ElRT
109-
nA_recompute::ElRT
110109

111110
# Logs and options
112111
log::LookAheadLanczosDecompLog
@@ -227,7 +226,7 @@ function LookAheadLanczosDecomp(
227226
D, E, Flastcol, Flastrow, F̃lastcol, G, H,
228227
U, L,
229228
n, k, l, kstar, lstar, mk, nl,
230-
false, false, nA, nA,
229+
false, false, nA,
231230
ld_log,
232231
LookAheadLanczosDecompOptions(
233232
max_iter,
@@ -311,7 +310,7 @@ function _update_PQ_sequence!(ld)
311310
# Alg. 5.2.3
312311
_update_Flastrow!(ld)
313312
# Alg. 5.2.4
314-
ld.innerp = inner_ok && _is_singular(ld.E)
313+
ld.innerp = inner_ok && !isempty(ld.E) && _is_singular(last(blocks(ld.E)))
315314
# Alg. 5.2.5
316315
_update_U!(ld, ld.innerp)
317316
# Alg. 5.2.6
@@ -374,7 +373,7 @@ function _update_VW_sequence!(ld)
374373
# Alg. 5.2.16
375374
_update_Flastcol!(ld)
376375
# Alg. 5.2.17
377-
ld.innerv = inner_ok && _is_singular(ld.D[ld.nl[ld.l]:end, ld.nl[ld.l]:end])
376+
ld.innerv = inner_ok && _is_singular(last(blocks(ld.D)))
378377
# Alg. 5.2.18
379378
_update_L!(ld, ld.innerv)
380379
# Alg. 5.2.19
@@ -436,7 +435,6 @@ function _update_D!(ld)
436435
# Eq. 3.15, (D Γ)ᵀ = (D Γ)
437436
# D[n, n] = wtv
438437

439-
# TODO: closed block
440438
if isone(ld.n) || _VW_block_size(ld) == 1
441439
_start_new_block!(ld.D, ld.wtv)
442440
else
@@ -464,7 +462,6 @@ function _update_Flastrow!(ld)
464462
# Note: D is at D_n, L is at L_{n-1}
465463
# Eq. 5.2 (w/ indices advanced):
466464
# F_{n} = D_{n}L[1:n, 1:n] + l[n+1, n]D_{n}[1:n, n+1][0 ... 0 1]
467-
# TODO: block
468465
if !isone(ld.n) # We only need to do this if we are constructing a block
469466
ld.Flastrow = reshape(ld.D[end:end, :] * ld.L, :)
470467
ld.F̃lastcol = ld.Flastrow .* ld.γ[1:end-1] ./ ld.γ[end]
@@ -589,7 +586,9 @@ function _append_PQ!(ld)
589586
end
590587

591588
# 5.2.4, 5.2.17
592-
_is_singular(A) = !isempty(A) && minimum(svdvals(A)) < eps(real(eltype(A)))
589+
# Freund, R. W., Gutknecht, M. H., & Nachtigal, N. M. (1993). An Implementation of the Look-Ahead Lanczos Algorithm for Non-Hermitian Matrices Part I. SIAM Journal on Scientific Computing, 14(1), 137–158. https://doi.org/10.1137/0914009
590+
# suggests eps()^(1/3)
591+
_is_singular(A) = !isempty(A) && minimum(svdvals(A)) < eps(real(eltype(A)))^(1/3)
593592

594593
function _update_E!(ld)
595594
# E = QtAP

src/limited_memory_matrices.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ function Base.show(io::IO, ::MIME"text/plain", A::LimitedMemoryMatrix) where {T}
6464
Base.showarg(io, A.value, true)
6565
end
6666

67+
function Base.show(io::IO, A::LimitedMemoryMatrix) where {T}
68+
print(io, Base.dims2string(size(A)), " ")
69+
Base.showarg(io, A.value, true)
70+
end
71+
6772
"""
6873
hcat!(A::LimitedMemoryMatrix, B::AbstractVector)
6974

test/lal.jl

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -238,35 +238,4 @@ end
238238

239239
test_lal_identities(ld_results)
240240
end
241-
end
242-
243-
@testset "Cyclic Circulant Matrix" begin
244-
rng = Random.Xoshiro(1234)
245-
# 4-cyclic circulant matrix, creates blocks
246-
I1 = Diagonal(fill(1.0, 3))
247-
I2 = Diagonal(fill(1.0, 7))
248-
I3 = Diagonal(fill(1.0, 3))
249-
I4 = Diagonal(fill(1.0, 5))
250-
B1 = rand(rng, size(I1, 1), size(I4, 2))
251-
B2 = rand(rng, size(I2, 1), size(I1, 2))
252-
B3 = rand(rng, size(I3, 1), size(I2, 2))
253-
B4 = rand(rng, size(I4, 1), size(I3, 2))
254-
Z12 = fill(0.0, size(I1, 1), size(I2, 2))
255-
Z13 = fill(0.0, size(I1, 1), size(I3, 2))
256-
Z14 = fill(0.0, size(I1, 1), size(I4, 2))
257-
Z23 = fill(0.0, size(I2, 1), size(I3, 2))
258-
Z24 = fill(0.0, size(I2, 1), size(I4, 2))
259-
Z34 = fill(0.0, size(I3, 1), size(I4, 2))
260-
Ac = [
261-
I1 Z12 Z13 B1
262-
B2 I2 Z23 Z24
263-
Z13' B3 I3 Z34
264-
Z14' Z24' B4 I4
265-
]
266-
v = [rand(rng, size(I1, 1)); fill(0.0, size(Ac, 1) - size(I1, 1))]
267-
w = [rand(rng, size(I1, 1)); fill(0.0, size(Ac, 1) - size(I1, 1))]
268-
ld = IS.LookAheadLanczosDecomp(Ac, v, w; log=true, vw_normalized=false, max_block_size=10, max_memory=10, verbose=true)
269-
ld_results = _iterate_and_collect_lal_intermediates(ld)
270-
test_lal_identities(ld_results)
271-
end
272-
241+
end

0 commit comments

Comments
 (0)