1
- using InfiniteLinearAlgebra, LinearAlgebra, BandedMatrices, InfiniteArrays, MatrixFactorizations, LazyArrays, FillArrays, SpecialFunctions, Test
2
- import LazyArrays: colsupport, rowsupport, MemoryLayout, DenseColumnMajor, TriangularLayout, resizedata!
1
+ using InfiniteLinearAlgebra, LinearAlgebra, BandedMatrices, InfiniteArrays, MatrixFactorizations, LazyArrays,
2
+ FillArrays, SpecialFunctions, Test, SemiseparableMatrices
3
+ import LazyArrays: colsupport, rowsupport, MemoryLayout, DenseColumnMajor, TriangularLayout, resizedata!, arguments
3
4
import LazyBandedMatrices: BroadcastBandedLayout
4
5
import BandedMatrices: _BandedMatrix, _banded_qr!, BandedColumns
5
- import InfiniteLinearAlgebra: partialqr!, AdaptiveQRData, AdaptiveLayout
6
+ import InfiniteLinearAlgebra: partialqr!, AdaptiveQRData, AdaptiveLayout, adaptiveqr
7
+ import SemiseparableMatrices: AlmostBandedLayout, VcatAlmostBandedLayout
6
8
7
9
8
10
@testset " Adaptive QR" begin
@@ -26,7 +28,7 @@ import InfiniteLinearAlgebra: partialqr!, AdaptiveQRData, AdaptiveLayout
26
28
end
27
29
28
30
@testset " AdaptiveQRFactors" begin
29
- A = _BandedMatrix (Vcat (Ones (1 ,∞), (1 : ∞)' , Ones (1 ,∞)), ∞, 1 , 1 )
31
+ A = _BandedMatrix (Vcat (Ones (1 ,∞), (1 : ∞)' , Ones (1 ,∞)), ∞, 1 , 1 )
30
32
F = qr (A);
31
33
@test F. factors[1 ,1 ] ≈ - sqrt (2 )
32
34
@test F. factors[100 ,100 ] ≈ qrunblocked (A[1 : 101 ,1 : 100 ]). factors[100 ,100 ]
@@ -39,7 +41,7 @@ import InfiniteLinearAlgebra: partialqr!, AdaptiveQRData, AdaptiveLayout
39
41
end
40
42
41
43
@testset " col/rowsupport" begin
42
- A = _BandedMatrix (Vcat (Ones (1 ,∞), (1 : ∞)' , Ones (1 ,∞)), ∞, 1 , 1 )
44
+ A = _BandedMatrix (Vcat (Ones (1 ,∞), (1 : ∞)' , Ones (1 ,∞)), ∞, 1 , 1 )
43
45
F = qr (A);
44
46
@test MemoryLayout (typeof (F. factors)) isa AdaptiveLayout{BandedColumns{DenseColumnMajor}}
45
47
@test bandwidths (F. factors) == (1 ,2 )
@@ -60,7 +62,7 @@ import InfiniteLinearAlgebra: partialqr!, AdaptiveQRData, AdaptiveLayout
60
62
end
61
63
62
64
@testset " Qmul" begin
63
- A = _BandedMatrix (Vcat (Ones (1 ,∞), (1 : ∞)' , Ones (1 ,∞)), ∞, 1 , 1 )
65
+ A = _BandedMatrix (Vcat (Ones (1 ,∞), (1 : ∞)' , Ones (1 ,∞)), ∞, 1 , 1 )
64
66
Q,R = qr (A);
65
67
b = Vcat ([1. ,2 ,3 ],Zeros (∞))
66
68
@test lmul! (Q, Base. copymutable (b)). datasize[1 ] == 4
@@ -91,7 +93,7 @@ import InfiniteLinearAlgebra: partialqr!, AdaptiveQRData, AdaptiveLayout
91
93
@test qr (A[1 : 3000 ,1 : 3000 ]). Q' b[1 : 3000 ] ≈ (F. Q' b)[1 : 3000 ]
92
94
@time J = A \ Vcat ([besselj (1 ,z)], Zeros (∞))
93
95
@test J[1 : 2000 ] ≈ [besselj (k,z) for k= 0 : 1999 ]
94
-
96
+
95
97
z = 10_000 ; # the bigger z the longer before we see convergence
96
98
A = BandedMatrix (0 => - 2 * (0 : ∞)/ z, 1 => Ones (∞), - 1 => Ones (∞))
97
99
@time J = A \ Vcat ([besselj (1 ,z)], Zeros (∞))
@@ -132,4 +134,77 @@ import InfiniteLinearAlgebra: partialqr!, AdaptiveQRData, AdaptiveLayout
132
134
@test F. Q[1 : 10 ,1 : 10 ] == Eye (10 )
133
135
@test F. R[1 : 10 ,1 : 10 ] == A[1 : 10 ,1 : 10 ]
134
136
end
137
+
138
+ @testset " almost-banded" begin
139
+ @testset " one-band" begin
140
+ A = Vcat (Ones (1 ,∞), BandedMatrix (0 => - Ones (∞), 1 => 1 : ∞))
141
+ @test MemoryLayout (typeof (A)) isa VcatAlmostBandedLayout
142
+ V = view (A,1 : 10 ,1 : 10 )
143
+ @test MemoryLayout (typeof (V)) isa VcatAlmostBandedLayout
144
+ @test A[1 : 10 ,1 : 10 ] isa AlmostBandedMatrix
145
+ @test AlmostBandedMatrix (V) == Matrix (V) == A[1 : 10 ,1 : 10 ]
146
+
147
+ C = cache (A);
148
+ @test C[1000 ,1000 ] ≡ 999.0
149
+ F = adaptiveqr (A);
150
+ partialqr! (F. factors. data,2 );
151
+ @test F. factors. data. data[1 : 3 ,1 : 5 ] ≈ qr (A[1 : 3 ,1 : 5 ]). factors
152
+ partialqr! (F. factors. data,3 );
153
+ @test F. factors. data. data[1 : 4 ,1 : 6 ] ≈ qr (A[1 : 4 ,1 : 6 ]). factors
154
+
155
+ F = adaptiveqr (A);
156
+ partialqr! (F. factors. data,10 );
157
+ @test F. factors[1 : 11 ,1 : 10 ] ≈ qr (A[1 : 11 ,1 : 10 ]). factors
158
+ @test F. τ[1 : 10 ] ≈ qr (A[1 : 11 ,1 : 10 ]). τ
159
+ partialqr! (F. factors. data,20 );
160
+ @test F. factors[1 : 21 ,1 : 20 ] ≈ qr (A[1 : 21 ,1 : 20 ]). factors
161
+
162
+ @test adaptiveqr (A). R[1 : 10 ,1 : 10 ] ≈ qr (A[1 : 11 ,1 : 10 ]). R
163
+
164
+ @test qr (A) isa MatrixFactorizations. QR{Float64,<: InfiniteLinearAlgebra.AdaptiveQRFactors }
165
+ @test factorize (A) isa MatrixFactorizations. QR{Float64,<: InfiniteLinearAlgebra.AdaptiveQRFactors }
166
+
167
+ @test (adaptiveqr (A) \ [ℯ; zeros (∞)])[1 : 1000 ] ≈ (qr (A) \ [ℯ; zeros (∞)])[1 : 1000 ] ≈ (A \ [ℯ; zeros (∞)])[1 : 1000 ] ≈ [1 / factorial (1.0 k) for k= 0 : 999 ]
168
+ end
169
+
170
+ @testset " two-bands" begin
171
+ B = BandedMatrix (0 => - Ones (∞), 2 => (1 : ∞). * (2 : ∞))
172
+ A = Vcat (Vcat (Ones (1 ,∞), ((- 1 ). ^ (0 : ∞))' ), B)
173
+ @test MemoryLayout (typeof (A)) isa VcatAlmostBandedLayout
174
+
175
+ @test qr (A) isa MatrixFactorizations. QR{Float64,<: InfiniteLinearAlgebra.AdaptiveQRFactors }
176
+ @test factorize (A) isa MatrixFactorizations. QR{Float64,<: InfiniteLinearAlgebra.AdaptiveQRFactors }
177
+ u = qr (A) \ [1 ; zeros (∞)]
178
+ x = 0.1
179
+ @test (exp (1 - x)* (- 1 + exp (2 + 2 x)))/ (- 1 + exp (4 )) ≈ dot (u[1 : 1000 ], x.^ (0 : 999 ))
180
+ u = qr (A) \ Vcat ([ℯ,1 / ℯ], zeros (∞))
181
+ @test u[1 : 1000 ] ≈ [1 / factorial (1.0 k) for k= 0 : 999 ]
182
+ u = qr (A) \ Vcat (ℯ,1 / ℯ, zeros (∞))
183
+ @test u[1 : 1000 ] ≈ [1 / factorial (1.0 k) for k= 0 : 999 ]
184
+
185
+ A = Vcat (Ones (1 ,∞), ((- 1.0 ). ^ (0 : ∞))' , B)
186
+ @test MemoryLayout (typeof (A)) isa VcatAlmostBandedLayout
187
+ u = A \ Vcat (ℯ,1 / ℯ, zeros (∞))
188
+ @test u[1 : 1000 ] ≈ [1 / factorial (1.0 k) for k= 0 : 999 ]
189
+
190
+ A = Vcat (Ones (1 ,∞), ((- 1 ). ^ (0 : ∞))' , B)
191
+ u = A \ Vcat (ℯ,1 / ℯ, zeros (∞))
192
+ @test u[1 : 1000 ] ≈ [1 / factorial (1.0 k) for k= 0 : 999 ]
193
+ end
194
+
195
+ @testset " more bands" begin
196
+ L = Vcat (Ones (1 ,∞), ((- 1 ). ^ (0 : ∞))' ,
197
+ BandedMatrix (- 1 => Ones (∞), 1 => Ones (∞), 2 => 4 : 2 : ∞, 3 => Ones (∞), 5 => Ones (∞)))
198
+ F = qr (L). factors. data;
199
+ resizedata! (F. data,13 ,19 )
200
+ @test F. data. data[2 ,8 ] == - 1
201
+ F = qr (L);
202
+ partialqr! (F,10 );
203
+ @test F. factors[1 : 10 ,1 : 10 ] ≈ qr (L[1 : 13 ,1 : 10 ]). factors[1 : 10 ,1 : 10 ]
204
+ @test qr (L). factors[1 : 10 ,1 : 10 ] ≈ qr (L[1 : 13 ,1 : 10 ]). factors[1 : 10 ,1 : 10 ]
205
+
206
+ u = L \ [1 ; 2 ; zeros (∞)]
207
+ @test L[1 : 1000 ,1 : 1000 ]* u[1 : 1000 ] ≈ [1 ; 2 ; zeros (998 )]
208
+ end
209
+ end
135
210
end
0 commit comments