1
- using InfiniteLinearAlgebra, BlockBandedMatrices, BlockArrays, BandedMatrices, InfiniteArrays, FillArrays, LazyArrays, Test, MatrixFactorizations, LinearAlgebra
1
+ using InfiniteLinearAlgebra, BlockBandedMatrices, BlockArrays, BandedMatrices, InfiniteArrays, FillArrays, LazyArrays, Test, MatrixFactorizations, LinearAlgebra, Random
2
2
import InfiniteLinearAlgebra: qltail, toeptail, tailiterate , tailiterate!, tail_de, ql_X!,
3
- InfToeplitz, PertToeplitz, TriToeplitz, InfBandedMatrix, householderparams, combine_two_Q, periodic_combine_two_Q, householderparams,
3
+ InfToeplitz, PertToeplitz, TriToeplitz, InfBandedMatrix,
4
4
rightasymptotics, QLHessenberg
5
5
import BlockBandedMatrices: isblockbanded, _BlockBandedMatrix
6
6
import MatrixFactorizations: QLPackedQ
44
44
45
45
include (" test_hessenbergq.jl" )
46
46
47
-
48
47
@testset " PertTriToeplitz QL" begin
49
48
A = Tridiagonal (Vcat (Float64[], Fill (2.0 ,∞)),
50
49
Vcat (Float64[2.0 ], Fill (0.0 ,∞)),
@@ -55,7 +54,6 @@ include("test_hessenbergq.jl")
55
54
end
56
55
end
57
56
58
-
59
57
@testset " Pert Hessenberg Toeplitz" begin
60
58
a = [1 ,2 ,5 ,0.5 ]
61
59
Random. seed! (0 )
100
98
end
101
99
end
102
100
103
-
104
101
@testset " Pert faux-periodic QL" begin
105
102
a = [0.5794879759059747 + 0.0im ,0.538107104952824 - 0.951620830938543im ,- 0.19352887774167749 - 0.3738926065520737im ,0.4314153362874331 ,0.0 ]
106
103
T = _BandedMatrix (a* Ones {ComplexF64} (1 ,∞), ∞, 3 ,1 )
119
116
@test Qn[1 : 10 ,1 : 10 ] * diagm (0 => [Ones (5 ); - (- 1 ). ^ (1 : 5 )]) ≈ Q[1 : 10 ,1 : 10 ]
120
117
@test diagm (0 => [Ones (5 ); - (- 1 ). ^ (1 : 5 )]) * Ln[1 : 10 ,1 : 10 ] ≈ L[1 : 10 ,1 : 10 ]
121
118
end
122
-
123
-
124
- function qdL (A)
125
- l,u = bandwidths (A)
126
- H = _BandedMatrix (A. data, ∞, l+ u- 1 , 1 )
127
- Q1,L1 = ql (H)
128
- D1, Q1, L1 = reduceband (A)
129
- T2 = _BandedMatrix (Lrightasymptotics (L1), ∞, l, u)
130
- l1 = L1[1 ,1 ]
131
- A2 = [[D1 l1 zeros (1 ,10 - size (D1,2 )- 1 )]; T2[1 : 10 - 1 ,1 : 10 ]] # TODO : remove
132
- B2 = _BandedMatrix (T2. data, ∞, l+ u- 2 , 2 )
133
- B2 = _BandedMatrix (T2. data, ∞, l+ u- 2 , 2 )
134
- D2, Q2, L2 = reduceband (B2)
135
- l2 = L2[1 ,1 ]
136
- # peroidic tail
137
- T3 = _BandedMatrix (Lrightasymptotics (L2), ∞, l+ 1 , u- 1 )
138
- A3 = [[D2 l2 zeros (1 ,10 - size (D2,2 )- 1 )]; T3[1 : 10 - 1 ,1 : 10 ]] # TODO : remove
139
-
140
- Q3,L3 = ql ( [A2[1 ,1 ] A2[1 : 1 ,2 : 3 ]; [Q2[1 : 3 ,1 : 1 ]' * T2[1 : 3 ,1 ] A3[1 : 1 ,1 : 2 ] ]])
141
-
142
- fd_data = hcat ([0 ; L3[:,1 ]; Q2[1 : 3 ,2 : 3 ]' * T2[1 : 3 ,1 ]], [L3[:,2 ]; T3[1 : 3 ,1 ]], [L3[2 ,3 ]; T3[1 : 4 ,2 ]])
143
- B3 = _BandedMatrix (Hcat (fd_data, T3. data), ∞, l+ u- 1 , 1 )
144
-
145
- ql (B3). L
146
- end
147
-
148
- @testset " quick-and-dirty L" begin
149
- for λ in (5 ,1 ,0.1 + 0.1im ,- 0.5 - 0.1im ), A in (BandedMatrix (3 => Fill (7 / 10 ,∞), 2 => Fill (1 ,∞), 0 => Fill (- λ,∞), - 1 => Fill (2im ,∞)),
150
- BandedMatrix (3 => Fill (7 / 10 ,∞), 2 => Fill (1 ,∞), 0 => Fill (- conj (λ),∞), - 1 => Fill (- 2im ,∞)))
151
- L∞ = qdL (A)[1 : 10 ,1 : 10 ]
152
- Ln = ql (A[1 : 1000 ,1 : 1000 ]). L[1 : 10 ,1 : 10 ]
153
- @test L∞ .* sign .(diag (L∞)) ≈ Matrix (Ln) .* sign .(diag (Ln))
154
- end
155
- for λ in (- 3 - 0.1im , 0.0 , - 1im )
156
- A = BandedMatrix (3 => Fill (7 / 10 ,∞), 2 => Fill (1 ,∞), 0 => Fill (- conj (λ),∞), - 1 => Fill (- 2im ,∞))
157
- @test abs (qdL (A)[1 ,1 ]) ≈ abs (ql (A[1 : 10000 ,1 : 10000 ]). L[1 ,1 ])
158
- end
159
- for λ in (1 + 2im ,)
160
- A = BandedMatrix (3 => Fill (7 / 10 ,∞), 2 => Fill (1 ,∞), 0 => Fill (- λ,∞), - 1 => Fill (2im ,∞))
161
- @test_throws DomainError qdL (A)
162
- end
163
- end
164
-
165
-
166
-
167
- function tail_de_j (a:: AbstractVector{T} , j) where T
168
- m = length (a)
169
- C = [view (a,m- 1 : - 1 : 1 ) Vcat (- a[end ]* Eye (m- 2 ), Zeros {T} (1 ,m- 2 ))]
170
- λ, V = eigen (C):: Eigen{T,T,Matrix{T},Vector{T}}
171
- n2 = abs2 .(λ[j])
172
- n2 ≥ abs2 (a[end ]) || throw (DomainError (a, " QL factorization does not exist. This could indicate that the operator is not Fredholm or that the dimension of the kernel exceeds that of the co-kernel. Try again with the adjoint." ))
173
- c_abs = sqrt ((n2 - abs2 (a[end ]))/ abs2 (V[1 ,j]))
174
- c_sgn = - sign (λ[j])/ sign (V[1 ,j]* a[end - 1 ] - V[2 ,j]* a[end ])
175
- c_sgn* c_abs* V[end : - 1 : 1 ,j]
176
- end
177
-
178
- @testset " non-uniqueness" begin
179
- a = [10.774290245267503 - 2.01600077393353im , - 0.21512211005762638 + 0.4071609685512763im , - 1.1744464421530598 + 0.6046364065537878im , 0.9690771351593747 + 0.24407852288135806im ,
180
- - 0.17679826119222275 - 1.0449912257889253im , 1.350321850620113 + 0.1195877826052787im , - 0.7557518148047799 - 0.809927665736972im , - 0.24869467464627973 + 0.06062801043516876im ,
181
- - 0.83619838577036 + 1.053001604590783im ,1.0 + 0.0im ]
182
-
183
- A = _BandedMatrix (reverse (a) * Ones {ComplexF64} (1 ,∞), ∞, length (a)- 2 , 1 )
184
- l,u = bandwidths (A)
185
- Q,L = ql (A)
186
- @test Q[1 : 10 ,1 : 11 ] * L[1 : 11 ,1 : 10 ] ≈ A[1 : 10 ,1 : 10 ]
187
-
188
- de = tail_de (a)
189
- de2 = tail_de_j (a, 2 )
190
-
191
- @test ! (de ≈ de2)
192
-
193
- X = [transpose (a); 0 transpose (de2)]
194
- F = ql_X! (X)
195
- @test X[1 ,1 : end - 1 ] ≈ de2
196
- factors = _BandedMatrix (Hcat ([zero (T); X[1 ,end - 1 ]; X[2 ,end - 1 : - 1 : 1 ]], [0 ; X[2 ,end : - 1 : 1 ]] * Ones {T} (1 ,∞)), ∞, l+ u, 1 )
197
- Q2,L2 = QLHessenberg (factors, Fill (F. Q,∞))
198
- @test Q2[1 : 10 ,1 : 11 ] * L2[1 : 11 ,1 : 10 ] ≈ A[1 : 10 ,1 : 10 ]
199
- @test Q2[1 : 10 ,1 : 11 ] * (Q2' )[1 : 11 ,1 : 10 ] ≈ I
200
- @test (Q2' )[1 : 10 ,1 : 100 ] * (Q2)[1 : 100 ,1 : 10 ] ≈ I
201
- @test (Q' )[1 : 10 ,1 : 100 ] * (Q)[1 : 100 ,1 : 10 ] ≈ I
202
-
203
- @test ! (abs (L2[1 ,1 ]) ≈ abs (L[1 ,1 ]))
204
- end
0 commit comments