@@ -138,20 +138,16 @@ import LazyArrays: AbstractCachedMatrix, resizedata!
138138 wf = x-> (1 - x)^ 2
139139 sqrtwf = x-> (1 - x)
140140 # compute Jacobi matrix via decomp
141- Jchol = cholesky_jacobimatrix (wf, P)
142- JqrQ = qr_jacobimatrix (wf, P)
143- JqrR = qr_jacobimatrix (wf, P, :R )
141+ Jchol,_ = cholesky_jacobimatrix (wf, P)
142+ JqrR,_ = qr_jacobimatrix (wf, P)
144143 # use alternative inputs
145144 sqrtW = (P \ (sqrtwf .(x) .* P))
146- JqrQalt = qr_jacobimatrix (sqrtW, P)
147- JqrRalt = qr_jacobimatrix (sqrtW, P, :R )
145+ JqrRalt,_ = qr_jacobimatrix (sqrtW, J)
148146 # compute Jacobi matrix via Lanczos
149147 Jlanc = jacobimatrix (LanczosPolynomial (@. (wf .(x)),Normalized (legendre (0 .. 1 ))))
150148 # Comparison with Lanczos
151149 @test Jchol[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
152- @test JqrQ[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
153150 @test JqrR[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
154- @test JqrQalt[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
155151 @test JqrRalt[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
156152 end
157153 @testset " QR case, w(x) = (1-x)^4" begin
@@ -161,19 +157,17 @@ import LazyArrays: AbstractCachedMatrix, resizedata!
161157 wf = x -> (1 - x)^ 4
162158 sqrtwf = x -> (1 - x)^ 2
163159 # compute Jacobi matrix via decomp
164- JqrQ = qr_jacobimatrix (wf, P)
165- JqrR = qr_jacobimatrix (wf, P, :R )
160+ JqrR,R = qr_jacobimatrix (wf, P)
166161 # use alternative inputs
167162 sqrtW = (P \ (sqrtwf .(x) .* P))
168- JqrQalt = qr_jacobimatrix (sqrtW, P)
169- JqrRalt = qr_jacobimatrix (sqrtW, P, :R )
163+ JqrRalt,Ralt = qr_jacobimatrix (sqrtW, J)
170164 # compute Jacobi matrix via Lanczos
171165 Jclass = jacobimatrix (Normalized (jacobi (4 ,0 ,0 .. 1 )))
172166 # Comparison with Lanczos
173- @test JqrQ[ 1 : 10 , 1 : 10 ] ≈ Jclass [1 : 10 ,1 : 10 ]
174- @test JqrR[1 : 10 ,1 : 10 ] ≈ Jclass[1 : 10 ,1 : 10 ]
175- @test JqrQalt[ 1 : 10 , 1 : 10 ] ≈ Jclass [1 : 10 ,1 : 10 ]
176- @test JqrRalt[1 : 10 ,1 : 10 ] ≈ Jclass[1 : 10 ,1 : 10 ]
167+ S = Diagonal ( sign .( diag (R [1 : 10 ,1 : 10 ])))
168+ @test JqrR[1 : 10 ,1 : 10 ] ≈ S * Jclass[1 : 10 ,1 : 10 ]* S
169+ S = Diagonal ( sign .( diag (Ralt [1 : 10 ,1 : 10 ])))
170+ @test JqrRalt[1 : 10 ,1 : 10 ] ≈ S * Jclass[1 : 10 ,1 : 10 ]* S
177171 end
178172 @testset " QR case, w(x) = (x)^2*(1-x)^4" begin
179173 P = Normalized (legendre (0 .. 1 ))
@@ -182,35 +176,24 @@ import LazyArrays: AbstractCachedMatrix, resizedata!
182176 wf = x-> (x)^ 2 * (1 - x)^ 4
183177 sqrtwf = x-> (x)* (1 - x)^ 2
184178 # compute Jacobi matrix via decomp
185- JqrQ = qr_jacobimatrix (wf, P)
186- JqrR = qr_jacobimatrix (wf, P, :R )
179+ JqrR,R = qr_jacobimatrix (wf, P)
187180 # use alternative inputs
188181 sqrtW = (P \ (sqrtwf .(x) .* P))
189- JqrQalt = qr_jacobimatrix (sqrtW, P)
190- JqrRalt = qr_jacobimatrix (sqrtW, P, :R )
182+ JqrRalt,_ = qr_jacobimatrix (sqrtW, J)
191183 # compute Jacobi matrix via Lanczos
192184 Jclass = jacobimatrix (Normalized (jacobi (4 ,2 ,0 .. 1 )))
193185 # Comparison with Lanczos
194- @test JqrQ[1 : 10 ,1 : 10 ] ≈ Jclass[1 : 10 ,1 : 10 ]
195- @test JqrR[1 : 10 ,1 : 10 ] ≈ Jclass[1 : 10 ,1 : 10 ]
196- @test JqrQalt[1 : 10 ,1 : 10 ] ≈ Jclass[1 : 10 ,1 : 10 ]
197- @test JqrRalt[1 : 10 ,1 : 10 ] ≈ Jclass[1 : 10 ,1 : 10 ]
198- # test consistency of resizing in succession
199- F = qr_jacobimatrix (wf, P);
200- resizedata! (JqrQ. dv,70 )
201- resizedata! (JqrQ. ev,70 )
202- @test JqrQ[1 : 5 ,1 : 5 ] ≈ F[1 : 5 ,1 : 5 ]
203- @test JqrQ[1 : 20 ,1 : 20 ] ≈ F[1 : 20 ,1 : 20 ]
204- @test JqrQ[50 : 70 ,50 : 70 ] ≈ F[50 : 70 ,50 : 70 ]
186+
187+ S = Diagonal (sign .(diag (R[1 : 10 ,1 : 10 ])))
188+ @test JqrR[1 : 10 ,1 : 10 ] ≈ S* Jclass[1 : 10 ,1 : 10 ]* S
189+ @test JqrRalt[1 : 10 ,1 : 10 ] ≈ S* Jclass[1 : 10 ,1 : 10 ]* S
205190 end
206191 @testset " BigFloat returns correct values" begin
207192 t = BigFloat (" 1.1" )
208193 P = Normalized (legendre (big (0 ).. big (1 )))
209194 X = jacobimatrix (P)
210- Xq = qr_jacobimatrix (t* I- X, P, :Q )
211- Xr = qr_jacobimatrix (t* I- X, P, :R )
212- @test Xq[1 : 20 ,1 : 20 ] ≈ Xr[1 : 20 ,1 : 20 ]
213- @test_broken Xq[1 : 20 ,1 : 20 ] ≈ cholesky_jacobimatrix (Symmetric ((t* I- X)^ 2 ), P)[1 : 20 ,1 : 20 ]
195+ Xr,R = qr_jacobimatrix (t* I- X, X)
196+ @test_broken Xr[1 : 20 ,1 : 20 ] ≈ cholesky_jacobimatrix (Symmetric ((t* I- X)^ 2 ), X)[1 : 20 ,1 : 20 ]
214197 end
215198 end
216199
0 commit comments