@@ -16,6 +16,7 @@ mutable struct LALQMRIterable{T, xT, MT, rT, lanczosT}
1616 G:: Vector{Givens{T}}
1717
1818 d:: LimitedMemoryMatrix{T, MT}
19+ dlast:: xT
1920end
2021
2122function lalqmr_iterable! (
@@ -54,13 +55,14 @@ function lalqmr_iterable!(
5455 t[1 ] = resnorm
5556
5657 tolerance = max (reltol * resnorm, abstol)
58+ dlast = similar (x)
5759
5860 return LALQMRIterable (
5961 x,
6062 lanczos, resnorm, tolerance,
6163 maxiter,
6264 t, R,
63- G, d
65+ G, d, dlast
6466 )
6567end
6668
@@ -83,29 +85,28 @@ function iterate(q::LALQMRIterable, n::Int=start(q))
8385 end
8486 gend, r = givens (Llastcol, n, n+ 1 )
8587 push! (q. G, gend)
86- Llastcol[end - 1 ] = r
88+ Llastcol[end - 1 ] = r # Llastcol[end] = 0, but we don't need it
8789 _grow_hcat! (q. R, Llastcol[1 : end - 1 ])
8890
89-
9091 # Eq. 6.2, update t
9192 push! (q. t, 0 )
92- q. t = gend * q. t
93+ q. t . = gend * q. t
9394
9495 # Eq. 6.3, calculate projection
9596 # Dn = [Vn Un^-1 Rn^-1]
9697 # => Dn Rn Un = Vn
9798 RU = q. R* q. lanczos. U
98- d = q. lanczos. V[ :, end - 1 ]
99+ copyto! (q . dlast, view ( q. lanczos. V, :, n))
99100 for i in 1 : size (RU, 1 )- 1
100101 if RU[i, end ] != 0
101- axpy! (- RU[i, end ], q. d[ :, i], d )
102+ axpy! (- RU[i, end ], view ( q. d, :, i), q . dlast )
102103 end
103104 end
104- d = d / RU[end , end ]
105- hcat! (q. d, d )
105+ q . dlast ./= RU[end , end ]
106+ hcat! (q. d, q . dlast )
106107
107108 # iterate x_n = x_n-1 + d_n τ_n
108- axpy! (q. t[end - 1 ], d , q. x)
109+ axpy! (q. t[end - 1 ], q . dlast , q. x)
109110
110111 # Eq. 4.12, Freund 1990
111112 q. resnorm = q. resnorm * abs (gend. s) * sqrt (n+ 1 )/ sqrt (n)
@@ -183,7 +184,8 @@ function lalqmr!(
183184 maxiter= maxiter,
184185 initially_zero= initially_zero,
185186 log= log,
186- verbose= verbose
187+ verbose= verbose,
188+ kwargs...
187189 )
188190
189191 verbose && @printf (" === qmr ===\n %4s\t %7s\n " ," iter" ," resnorm" )
0 commit comments