Skip to content

Commit 011c631

Browse files
author
Pawel Latawiec
committed
Reduce F to only store last row/col
1 parent 98e4c42 commit 011c631

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

src/lal.jl

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ mutable struct LookAheadLanczosDecomp{OpT, OptT, VecT, MatT, ElT, ElRT}
7777
# Eq. 3.14
7878
E::BlockDiagonal{ElT, Matrix{ElT}}
7979
# Defined after Eq. 5.1
80-
F::Matrix{ElT}
80+
Flastcol::Vector{ElT} # size n
81+
Flastrow::Vector{ElT} # size n-1
8182
F̃lastcol::Vector{ElT}
8283
# Eq. 5.1
8384
G::Vector{ElT}
@@ -184,7 +185,8 @@ function LookAheadLanczosDecomp(
184185
G = Vector{elT}()
185186
H = Vector{elT}()
186187

187-
F = Matrix{elT}(undef, 0, 0)
188+
Flastcol = Vector{elT}()
189+
Flastrow = Vector{elT}()
188190
F̃lastcol = Vector{elT}()
189191

190192
U = UpperTriangular(Matrix{elT}(undef, 0, 0))
@@ -222,7 +224,7 @@ function LookAheadLanczosDecomp(
222224
qtAp, w̃tṽ, wtv,
223225
normp, normq, ρ, ξ,
224226
γ,
225-
D, E, F, F̃lastcol, G, H,
227+
D, E, Flastcol, Flastrow, F̃lastcol, G, H,
226228
U, L,
227229
n, k, l, kstar, lstar, mk, nl,
228230
false, false, nA, nA,
@@ -438,9 +440,9 @@ function _update_D!(ld)
438440
if isone(ld.n) || _VW_block_size(ld) == 1
439441
_start_new_block!(ld.D, ld.wtv)
440442
else
441-
D_lastcol = (ld.F[:, end] - (ld.D * ld.L[1:end-1, end])) / ld.ρ
442-
D_lastrow = transpose(D_lastcol * ld.γ[end] ./ ld.γ[1:end-1])
443-
_grow_last_block!(ld.D, D_lastcol, D_lastrow, ld.wtv)
443+
Dlastcol = (ld.Flastcol - (ld.D * ld.L[1:end-1, end])) / ld.ρ
444+
Dlastrow = transpose(Dlastcol * ld.γ[end] ./ ld.γ[1:end-1])
445+
_grow_last_block!(ld.D, Dlastcol, Dlastrow, ld.wtv)
444446
end
445447
return ld
446448
end
@@ -464,13 +466,8 @@ function _update_Flastrow!(ld)
464466
# F_{n} = D_{n}L[1:n, 1:n] + l[n+1, n]D_{n}[1:n, n+1][0 ... 0 1]
465467
# TODO: block
466468
if !isone(ld.n) # We only need to do this if we are constructing a block
467-
Flastrow = ld.D[end:end, :] * ld.L
468-
ld.F̃lastcol = reshape(Flastrow, :) .* ld.γ[1:end-1] ./ ld.γ[end]
469-
# we are not able to fill in the last column yet, so we fill with zero
470-
ld.F = [
471-
ld.F fill(0.0, size(ld.F, 1))
472-
Flastrow 0.0
473-
]
469+
ld.Flastrow = reshape(ld.D[end:end, :] * ld.L, :)
470+
ld.F̃lastcol = ld.Flastrow .* ld.γ[1:end-1] ./ ld.γ[end]
474471
end
475472
end
476473

@@ -603,7 +600,7 @@ function _update_E!(ld)
603600
_start_new_block!(ld.E, ld.qtAp)
604601
else
605602
ΓUtinvΓ = ld.γ .* transpose(ld.U) ./ transpose(ld.γ)
606-
Elastrow = (ΓUtinvΓ[end, end] \ ld.F[n:n, 1:n-1] - ΓUtinvΓ[end:end, 1:end-1]*ld.E)
603+
Elastrow = (ΓUtinvΓ[end, end] \ reshape(ld.Flastrow, 1, :) - ΓUtinvΓ[end:end, 1:end-1]*ld.E)
607604
Elastcol = (transpose(Elastrow) .* ld.γ[1:n-1] ./ ld.γ[n])
608605
_grow_last_block!(ld.E, Elastcol, Elastrow, ld.qtAp)
609606
end
@@ -624,9 +621,9 @@ function _update_Flastcol!(ld)
624621
ΓUtinvΓ = ld.γ .* transpose(ld.U) ./ transpose(ld.γ)
625622
# length n, ld.F_lastrow of length n-1
626623
if isone(n)
627-
ld.F = fill(ΓUtinvΓ[end, end] * ld.E[end, end], 1, 1)
624+
ld.Flastcol = fill(ΓUtinvΓ[end, end] * ld.E[end, end], 1)
628625
else
629-
ld.F[:, end] .= ΓUtinvΓ * ld.E[:, end]
626+
ld.Flastcol = ΓUtinvΓ * ld.E[:, end]
630627
end
631628
return ld
632629
end
@@ -638,10 +635,10 @@ function _update_L!(ld, innerv)
638635
for i = lstar:l-1
639636
block_start = nl[i]
640637
block_end = nl[i+1]-1
641-
Llastcol[block_start:block_end] .= blocks(ld.D)[i] \ ld.F[block_start:block_end, end]
638+
Llastcol[block_start:block_end] .= blocks(ld.D)[i] \ ld.Flastcol[block_start:block_end]
642639
end
643640
if !innerv
644-
Llastcol[nl[l]:end] .= blocks(ld.D)[end] \ ld.F[nl[l]:end, end]
641+
Llastcol[nl[l]:end] .= blocks(ld.D)[end] \ ld.Flastcol[nl[l]:end]
645642
end
646643
if isone(n)
647644
ld.L = UpperHessenberg(

test/lal.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ function _iterate_and_collect_lal_intermediates(ld)
4747
γ = copy(ld.γ) # size n+1
4848
D = copy(ld.D) # size (n, n)
4949
E = copy(ld.E) # size (n, n)
50-
F = copy(ld.F) # size (n, n)
51-
= copy(ld.F) # size (n, n)
50+
F = Matrix{eltype(ld.Flastcol)}(undef, 0, 0) # size (n, n)
51+
= copy(F) # size (n, n)
5252
U = copy(ld.U) # size (n, n)
5353
L = copy(ld.L) # size (n+1, n)
5454
Γ = Diagonal(γ) # size (n+1, n+1)
@@ -63,15 +63,14 @@ function _iterate_and_collect_lal_intermediates(ld)
6363
if (i==1)
6464
D = ld.D[:, :]
6565
E = ld.E[:, :]
66-
F = ld.F[:, :]
66+
F = ld.Flastcol[:, :]
6767
= (transpose(F * Γ[1:end-1, 1:end-1]) / Γ[1:end-1, 1:end-1])
6868
U = ld.U[:, :]
6969
L = ld.L[:, :]
7070
else
71-
ivw = IS._VW_block_size(ld)
7271
D = _append_leading_nonzeros(D, ld.D)
7372
E = _append_leading_nonzeros(E, ld.E)
74-
F = _append_leading_nonzeros(F, ld.F)
73+
F = [[F; transpose(ld.Flastrow)] ld.Flastcol]
7574
# F̃ row is not explicitly calculated, so we calculate from F using Lemma 5.1
7675
= [F̃ ld.F̃lastcol; (transpose(F * Γ[1:end-1, 1:end-1]) / Γ[1:end-1, 1:end-1])[end:end, :]]
7776
U = _append_leading_nonzeros(U, ld.U)

0 commit comments

Comments
 (0)