@@ -3,6 +3,7 @@ using InfiniteLinearAlgebra: BidiagonalConjugation, OneToInf
33using ArrayLayouts: supdiagonaldata, subdiagonaldata, diagonaldata
44using LinearAlgebra
55using LazyArrays: LazyLayout
6+ using BandedMatrices: _BandedMatrix
67
78@testset " BidiagonalConjugation" begin
89 @test InfiniteLinearAlgebra. _to_uplo (' U' ) == ' U'
@@ -102,11 +103,25 @@ end
102103
103104
104105@testset " TridiagonalConjugation" begin
105- @testset " T -> U" begin
106- R = BandedMatrices. _BandedMatrix (Vcat (- Ones (1 ,∞)/ 2 ,
107- Zeros (1 ,∞),
108- Hcat (Ones (1 ,1 ),Ones (1 ,∞)/ 2 )), ℵ₀, 0 ,2 )
109- X_T = LazyBandedMatrices. Tridiagonal (Vcat (1.0 , Fill (1 / 2 ,∞)), Zeros (∞), Fill (1 / 2 ,∞))
106+ for (R,X_T) in (
107+ # T -> U
108+ (_BandedMatrix (Vcat (- Ones (1 ,∞)/ 2 , Zeros (1 ,∞), Hcat (Ones (1 ,1 ),Ones (1 ,∞)/ 2 )), ℵ₀, 0 ,2 ),
109+ LazyBandedMatrices. Tridiagonal (Vcat (1.0 , Fill (1 / 2 ,∞)), Zeros (∞), Fill (1 / 2 ,∞))),
110+ # P -> C^(3/2)
111+ (_BandedMatrix (Vcat ((- 1 ./ (1 : 2 : ∞))' ,
112+ Zeros (1 ,∞),
113+ (1 ./ (1 : 2 : ∞))' ), ℵ₀, 0 ,2 ),
114+ LazyBandedMatrices. Tridiagonal ((1 : ∞) ./ (1 : 2 : ∞), Zeros (∞), (1 : ∞) ./ (3 : 2 : ∞))),
115+ # P^(1,0) -> P^(2,0)
116+ (_BandedMatrix (Vcat (Zeros (1 ,∞), # extra band since code assumes two bands
117+ (- (0 : ∞) ./ (2 : 2 : ∞))' ,
118+ ((2 : ∞) ./ (2 : 2 : ∞))' ), ℵ₀, 0 ,2 ),
119+ LazyBandedMatrices. Tridiagonal ((2 : ∞) ./ (3 : 2 : ∞), - 1 ./ ((1 : 2 : ∞) .* (3 : 2 : ∞)), (1 : ∞) ./ (3 : 2 : ∞))),
120+ # P -> C^(5/2)
121+ (_BandedMatrix (Vcat ((- 3 ./ (3 : 2 : ∞))' , Zeros (1 ,∞), (3 ./ (3 : 2 : ∞))' ), ℵ₀, 0 ,2 ) *
122+ _BandedMatrix (Vcat ((- 1 ./ (1 : 2 : ∞))' , Zeros (1 ,∞), (1 ./ (1 : 2 : ∞))' ), ℵ₀, 0 ,2 ),
123+ LazyBandedMatrices. Tridiagonal ((1 : ∞) ./ (1 : 2 : ∞), Zeros (∞), (1 : ∞) ./ (3 : 2 : ∞)))
124+ )
110125 n = 1000
111126 @time U = V = R[1 : n,1 : n];
112127 @time X = Tridiagonal (Vector (X_T. dl[1 : n- 1 ]), Vector (X_T. d[1 : n]), Vector (X_T. du[1 : n- 1 ]));
@@ -116,50 +131,31 @@ end
116131 @time Y = InfiniteLinearAlgebra. tri_mul_invupper_triview (UX, U)
117132 @test Tridiagonal (U* X / U) ≈ Tridiagonal (UX / U) ≈ Y
118133
119- InfiniteLinearAlgebra. TridiagonalConjugationData (U, X, U)
120- end
121- @testset " P -> Ultraspherical(3/2)" begin
122- R = BandedMatrices. _BandedMatrix (Vcat ((- 1 ./ (1 : 2 : ∞))' ,
123- Zeros (1 ,∞),
124- (1 ./ (1 : 2 : ∞))' ), ℵ₀, 0 ,2 )
125- X_P = LazyBandedMatrices. Tridiagonal ((1 : ∞) ./ (1 : 2 : ∞), Zeros (∞), (1 : ∞) ./ (3 : 2 : ∞))
126- n = 1000
127- @time U = V = R[1 : n,1 : n]
128- @time X = Tridiagonal (Vector (X_P. dl[1 : n- 1 ]), Vector (X_P. d[1 : n]), Vector (X_P. du[1 : n- 1 ]))
129- @time UX = InfiniteLinearAlgebra. upper_mul_tri_triview (U, X)
130- @test Tridiagonal (U* X) ≈ UX
131- # U*X*inv(U) only depends on Tridiagonal(U*X)
132- @time Y = InfiniteLinearAlgebra. tri_mul_invupper_triview (UX, U)
133- @test Tridiagonal (U* X / U) ≈ Tridiagonal (UX / U) ≈ Y
134- end
134+ data = InfiniteLinearAlgebra. TridiagonalConjugationData (R, X_T)
135+ @test data. UX[1 ,:] ≈ UX[1 ,1 : 100 ]
136+ InfiniteLinearAlgebra. resizedata! (data, 1 )
137+ @test data. UX[1 : 2 ,:] ≈ UX[1 : 2 ,1 : 100 ]
138+ @test data. Y[1 ,:] ≈ Y[1 ,1 : 100 ]
139+ InfiniteLinearAlgebra. resizedata! (data, 2 )
140+ @test data. UX[1 : 3 ,:] ≈ UX[1 : 3 ,1 : 100 ]
141+ @test data. Y[1 : 2 ,:] ≈ Y[1 : 2 ,1 : 100 ]
142+ InfiniteLinearAlgebra. resizedata! (data, 3 )
143+ @test data. UX[1 : 4 ,:] ≈ UX[1 : 4 ,1 : 100 ]
144+ @test data. Y[1 : 3 ,:] ≈ Y[1 : 3 ,1 : 100 ]
145+ InfiniteLinearAlgebra. resizedata! (data, 1000 )
146+ @test data. UX[1 : 999 ,1 : 999 ] ≈ UX[1 : 999 ,1 : 999 ]
147+ @test data. Y[1 : 999 ,1 : 999 ] ≈ Y[1 : 999 ,1 : 999 ]
135148
136- @testset " Jacobi(1,0) -> Jacobi(2,0)" begin
137- R = BandedMatrices. _BandedMatrix (Vcat (Zeros (1 ,∞), # extra band since code assumes two bands
138- (- (0 : ∞) ./ (2 : 2 : ∞))' ,
139- ((2 : ∞) ./ (2 : 2 : ∞))' ), ℵ₀, 0 ,2 )
140- X_P = LazyBandedMatrices. Tridiagonal ((2 : ∞) ./ (3 : 2 : ∞), - 1 ./ ((1 : 2 : ∞) .* (3 : 2 : ∞)), (1 : ∞) ./ (3 : 2 : ∞))
141- n = 1000
142- @time U = V = R[1 : n,1 : n]
143- @time X = Tridiagonal (Vector (X_P. dl[1 : n- 1 ]), Vector (X_P. d[1 : n]), Vector (X_P. du[1 : n- 1 ]))
144- @time UX = InfiniteLinearAlgebra. upper_mul_tri_triview (U, X)
145- @test Tridiagonal (U* X) ≈ UX
146- # U*X*inv(U) only depends on Tridiagonal(U*X)
147- @time Y = InfiniteLinearAlgebra. tri_mul_invupper_triview (UX, U)
148- @test Tridiagonal (U* X / U) ≈ Tridiagonal (UX / U) ≈ Y
149+ data = InfiniteLinearAlgebra. TridiagonalConjugationData (R, X_T)
150+ InfiniteLinearAlgebra. resizedata! (data, 1000 )
151+ @test data. UX[1 : 999 ,1 : 999 ] ≈ UX[1 : 999 ,1 : 999 ]
152+ @test data. Y[1 : 999 ,1 : 999 ] ≈ Y[1 : 999 ,1 : 999 ]
149153 end
150-
151- @testset " Legendre() -> Jacobi(5/2)" begin
152- R = BandedMatrices. _BandedMatrix (Vcat ((- 3 ./ (3 : 2 : ∞))' , Zeros (1 ,∞), (3 ./ (3 : 2 : ∞))' ), ℵ₀, 0 ,2 ) *
153- BandedMatrices. _BandedMatrix (Vcat ((- 1 ./ (1 : 2 : ∞))' , Zeros (1 ,∞), (1 ./ (1 : 2 : ∞))' ), ℵ₀, 0 ,2 )
154- X_P = LazyBandedMatrices. Tridiagonal ((1 : ∞) ./ (1 : 2 : ∞), Zeros (∞), (1 : ∞) ./ (3 : 2 : ∞))
155-
156- n = 1000
157- @time U = V = R[1 : n,1 : n]
158- @time X = Tridiagonal (Vector (X_P. dl[1 : n- 1 ]), Vector (X_P. d[1 : n]), Vector (X_P. du[1 : n- 1 ]))
159- @time UX = InfiniteLinearAlgebra. upper_mul_tri_triview (U, X)
160- @test Tridiagonal (U* X) ≈ UX
161- # U*X*inv(U) only depends on Tridiagonal(U*X)
162- @time Y = InfiniteLinearAlgebra. tri_mul_invupper_triview (UX, U)
163- @test Tridiagonal (U* X / U) ≈ Tridiagonal (UX / U) ≈ Y
154+
155+ @testset " Cholesky" begin
156+ M = Symmetric (_BandedMatrix (Vcat (Hcat (Fill (- 1 / (2 sqrt (2 )),1 ,3 ), Fill (- 1 / 4 ,1 ,∞)), Zeros (1 ,∞), Hcat ([0.5 0.25 ], Fill (0.5 ,1 ,∞))), ∞, 0 , 2 ))
157+ R = cholesky (M). U
158+ X_T = LazyBandedMatrices. Tridiagonal (Vcat (1 / sqrt (2 ), Fill (1 / 2 ,∞)), Zeros (∞), Vcat (1 / sqrt (2 ), Fill (1 / 2 ,∞)))
159+ data = InfiniteLinearAlgebra. TridiagonalConjugationData (R, X_T)
164160 end
165161end
0 commit comments