@@ -2,7 +2,7 @@ import Base: iterate
2
2
3
3
export lalqmr, lalqmr!
4
4
5
- mutable struct LALQMRIterable{T, xT, rT, lanczosT}
5
+ mutable struct LALQMRIterable{T, xT, MT, rT, lanczosT}
6
6
x:: xT
7
7
8
8
lanczos:: lanczosT
@@ -11,11 +11,11 @@ mutable struct LALQMRIterable{T, xT, rT, lanczosT}
11
11
maxiter:: Int
12
12
13
13
t:: Vector{T}
14
- R:: UpperTriangular {T, Matrix{T}}
14
+ R:: LimitedMemoryUpperTriangular {T, Matrix{T}}
15
15
16
16
G:: Vector{Givens{T}}
17
17
18
- d:: Matrix{T }
18
+ d:: LimitedMemoryMatrix{T, MT }
19
19
end
20
20
21
21
function lalqmr_iterable! (
@@ -24,6 +24,7 @@ function lalqmr_iterable!(
24
24
reltol:: Real = sqrt (eps (real (eltype (b)))),
25
25
maxiter:: Int = size (A, 2 ),
26
26
initially_zero:: Bool = false ,
27
+ max_memory:: Int = 4 ,
27
28
kwargs...
28
29
)
29
30
T = eltype (x)
@@ -37,16 +38,17 @@ function lalqmr_iterable!(
37
38
38
39
lanczos = LookAheadLanczosDecomp (
39
40
A, v, w;
40
- vw_normalized = true ,
41
+ vw_normalized= true ,
42
+ max_memory= max_memory,
41
43
kwargs...
42
44
)
43
45
44
- R = UpperTriangular ( Matrix {T} (undef, 0 , 0 ) )
46
+ R = LimitedMemoryUpperTriangular {T, Matrix{T}} (max_memory )
45
47
# Givens rotations
46
48
G = Vector {Givens{T}} ()
47
49
48
50
# Projection operators
49
- D = similar (x, size (x , 1 ), 0 )
51
+ d = LimitedMemoryMatrix ( similar (x, size (v , 1 ), 0 ), max_memory )
50
52
51
53
t = Vector {T} (undef, 1 )
52
54
t[1 ] = resnorm
@@ -58,7 +60,7 @@ function lalqmr_iterable!(
58
60
lanczos, resnorm, tolerance,
59
61
maxiter,
60
62
t, R,
61
- G, D
63
+ G, d
62
64
)
63
65
end
64
66
@@ -82,9 +84,7 @@ function iterate(q::LALQMRIterable, n::Int=start(q))
82
84
gend, r = givens (Llastcol, n, n+ 1 )
83
85
push! (q. G, gend)
84
86
Llastcol[end - 1 ] = r
85
- Llastcol[end ] = 0
86
- q. R = UpperTriangular ([[q. R; fill (0 , 1 , n- 1 )] Llastcol[1 : end - 1 ]])
87
- @assert q. R[:, end ] ≈ Llastcol[1 : end - 1 ]
87
+ _grow_hcat! (q. R, Llastcol[1 : end - 1 ])
88
88
89
89
90
90
# Eq. 6.2, update t
@@ -97,10 +97,12 @@ function iterate(q::LALQMRIterable, n::Int=start(q))
97
97
RU = q. R* q. lanczos. U
98
98
d = q. lanczos. V[:, end - 1 ]
99
99
for i in 1 : size (RU, 1 )- 1
100
- axpy! (- RU[i, end ], q. d[:, i], d)
100
+ if RU[i, end ] != 0
101
+ axpy! (- RU[i, end ], q. d[:, i], d)
102
+ end
101
103
end
102
104
d = d / RU[end , end ]
103
- q. d = [q . d d]
105
+ hcat! ( q. d, d)
104
106
105
107
# iterate x_n = x_n-1 + d_n τ_n
106
108
axpy! (q. t[end - 1 ], d, q. x)
0 commit comments