@@ -6,7 +6,7 @@ using Test
6
6
# Equation references and identities from:
7
7
# Freund, R. W., & Nachtigal, N. M. (1994). An Implementation of the QMR Method Based on Coupled Two-Term Recurrences. SIAM Journal on Scientific Computing, 15(2), 313–337. https://doi.org/10.1137/0915022
8
8
9
- function _iterate_and_test_intermediates (ld)
9
+ function _iterate_and_collect_lal_intermediates (ld)
10
10
# iterates through ld and collects the intermediate matrices by appending the last
11
11
# row and column to the matrix being built
12
12
# returns a NamedTuple with the same names as `ld`
@@ -52,16 +52,13 @@ function _iterate_and_test_intermediates(ld)
52
52
F̃ = [F̃ ld. F̃lastcol; (transpose (F * Γ[1 : end - 1 , 1 : end - 1 ]) / Γ[1 : end - 1 , 1 : end - 1 ])[end : end , :]]
53
53
U = [U ld. U[1 : end - 1 , end ]; ld. U[end : end , :]]
54
54
L = [L ld. L[1 : end - 1 , end ]; ld. L[end : end , :]]
55
-
56
- results = (P= P, Q= Q, W= W, V= V, γ= γ, Γ= Γ, D= D, E= E, F= F, F̃= F̃, U= U, L= L, n= ld. n, A= ld. A, At= ld. At)
57
- _test_lal_identities (results)
58
55
end
59
56
end
60
57
61
58
return (P= P, Q= Q, W= W, V= V, γ= γ, Γ= Γ, D= D, E= E, F= F, F̃= F̃, U= U, L= L, n= ld. n, A= ld. A, At= ld. At)
62
59
end
63
60
64
- function _test_lal_identities (ld)
61
+ function test_lal_identities (ld)
65
62
# Note: V, W, Γ are all at n+1, but the values at n are use for some identities
66
63
Vn = ld. V[:, 1 : end - 1 ]
67
64
Wn = ld. W[:, 1 : end - 1 ]
@@ -121,7 +118,7 @@ function _test_lal_identities(ld)
121
118
@test all ([norm (ld. W[:, i]) for i in axes (ld. W, 2 )] .≈ 1 )
122
119
end
123
120
124
- function test_regular_identities (ld, log; early_exit= false )
121
+ function test_regular_lal_identities (ld, log; early_exit= false )
125
122
# If all regular vectors, expect:
126
123
# Eq. 3.22, U is upper triangular (bi-diagonal)
127
124
@test tril (ld. U, 1 ) ≈ triu (ld. U)
@@ -143,15 +140,15 @@ end
143
140
v = rand (5 )
144
141
w = rand (5 )
145
142
ld = IS. LookAheadLanczosDecomp (A, v, w; log= true , vw_normalized= false )
146
- ld_results = _iterate_and_test_intermediates (ld)
143
+ ld_results = _iterate_and_collect_lal_intermediates (ld)
147
144
148
145
@test ld. n == 1
149
146
@test ld_results. V ≈ v
150
147
@test ld_results. W ≈ w
151
148
@test isempty (ld_results. P)
152
149
@test isempty (ld_results. Q)
153
150
154
- test_regular_identities (ld_results, ld. log; early_exit= true )
151
+ test_regular_lal_identities (ld_results, ld. log; early_exit= true )
155
152
end
156
153
157
154
@testset " Dense Hermitian Matrix" begin
@@ -162,20 +159,64 @@ end
162
159
w = fill (0.0im , 10 )
163
160
w[1 : 2 ] .= 1.0
164
161
ld = IS. LookAheadLanczosDecomp (A, v, w; log= true , vw_normalized= false )
165
- ld_results = _iterate_and_test_intermediates (ld)
166
- test_regular_identities (ld_results, ld. log)
162
+ ld_results = _iterate_and_collect_lal_intermediates (ld)
163
+
164
+ test_lal_identities (ld_results)
165
+ test_regular_lal_identities (ld_results, ld. log)
167
166
end
168
167
169
168
170
169
@testset " Sparse Tri-diagonal Matrix" begin
171
170
A = Tridiagonal (- ones (9 ), 2 * ones (10 ), - ones (9 ))
172
- v = fill (0.0im , 10 )
173
- v[1 ] = 1.0
174
- w = fill (0.0im , 10 )
175
- w[1 ] = 1.0
176
- ld = IS. LookAheadLanczosDecomp (A, v, w; log= true , vw_normalized= false )
177
- ld_results = _iterate_and_test_intermediates (ld)
178
- test_regular_identities (ld_results, ld. log)
171
+ v = fill (0.0 , 10 )
172
+ w = fill (0.0 , 10 )
173
+ @testset " Regular Construction" begin
174
+ fill! (v, 0 )
175
+ fill! (w, 0 )
176
+ v[1 ] = 1.0
177
+ w[1 ] = 1.0
178
+ ld = IS. LookAheadLanczosDecomp (A, v, w; log= true , vw_normalized= false )
179
+ ld_results = _iterate_and_collect_lal_intermediates (ld)
180
+
181
+ test_lal_identities (ld_results)
182
+ test_regular_lal_identities (ld_results, ld. log)
183
+ end
184
+ @testset " Size 2 V-W Blocks" begin
185
+ fill! (v, 0 )
186
+ fill! (w, 0 )
187
+ v[1 ] = 1.0
188
+ w[2 ] = 1.0
189
+ ld = IS. LookAheadLanczosDecomp (A, v, w; log= true , vw_normalized= false , max_block_size= 2 )
190
+ ld_results = _iterate_and_collect_lal_intermediates (ld)
191
+
192
+ test_lal_identities (ld_results)
193
+ @test ld. log. VW_block_count[2 ] == 5
194
+ @test ld. log. PQ_block_count[1 ] == 10
195
+ end
196
+ @testset " Size 3 V-W Blocks, size 2 P-Q Blocks" begin
197
+ fill! (v, 0 )
198
+ fill! (w, 0 )
199
+ v[1 ] = 1.0
200
+ w[3 ] = 1.0
201
+ ld = IS. LookAheadLanczosDecomp (A, v, w; log= true , vw_normalized= false , max_block_size= 3 )
202
+ ld_results = _iterate_and_collect_lal_intermediates (ld)
203
+
204
+ test_lal_identities (ld_results)
205
+ @test ld. log. VW_block_count[3 ] == 3
206
+ @test ld. log. PQ_block_count[2 ] == 3
207
+ @test ld. log. PQ_block_count[1 ] == 3
208
+ end
209
+ @testset " Regular V-W, immediate P-Q Block" begin
210
+ # v, w chosen s.t (w, v) ≠ 0 and (q, Ap) == (w, Av) == 0
211
+ fill! (v, 0 )
212
+ fill! (w, 0 )
213
+ v[1 ] = 1.0
214
+ w[1 : 2 ] .= [1.0 ; 2.0 ]
215
+ ld = IS. LookAheadLanczosDecomp (A, v, w; log= true , vw_normalized= false )
216
+ ld_results = _iterate_and_collect_lal_intermediates (ld)
217
+
218
+ test_lal_identities (ld_results)
219
+ end
179
220
end
180
221
181
222
@testset " Cyclic Circulant Matrix" begin
200
241
Z13' B3 I3 Z34
201
242
Z14' Z24' B4 I4
202
243
]
203
- v = [ones (size (I1, 1 )); fill (0.0 , size (Ac, 1 ) - size (I1, 1 ))]
204
- w = [ones (size (I1, 1 )); fill (0.0 , size (Ac, 1 ) - size (I1, 1 ))]
244
+ v = [rand (size (I1, 1 )); fill (0.0 , size (Ac, 1 ) - size (I1, 1 ))]
245
+ w = [rand (size (I1, 1 )); fill (0.0 , size (Ac, 1 ) - size (I1, 1 ))]
205
246
ld = IS. LookAheadLanczosDecomp (Ac, v, w; log= true , vw_normalized= false , max_block_size= 8 , verbose= true )
206
- ld_results = _iterate_and_test_intermediates (ld)
247
+ ld_results = _iterate_and_collect_lal_intermediates (ld)
248
+ test_lal_identities (ld_results)
207
249
end
208
250
0 commit comments