Skip to content

Commit 7d7dcb1

Browse files
committed
basic Clenshaw tests
1 parent e8339aa commit 7d7dcb1

File tree

1 file changed

+70
-3
lines changed

1 file changed

+70
-3
lines changed

test/test_decompOPs.jl

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Test, ClassicalOrthogonalPolynomials, BandedMatrices, LinearAlgebra, LazyArrays, ContinuumArrays, LazyBandedMatrices
22
import ClassicalOrthogonalPolynomials: symmjacobim, CholeskyJacobiBands
33
import LazyArrays: AbstractCachedMatrix
4+
import LazyBandedMatrices: SymTridiagonal
45

56
@testset "Basic properties" begin
67
@testset "Test the Q&D conversion to BandedMatrix format" begin
@@ -35,12 +36,11 @@ import LazyArrays: AbstractCachedMatrix
3536
Cbands = CholeskyJacobiBands(w)
3637
@test Cbands isa CholeskyJacobiBands
3738
@test Cbands isa AbstractCachedMatrix
38-
@test Cbands[1,100] == (Cbands[1,1:100])[100]
39-
@test Cbands[:,50] == [Cbands[1,50],Cbands[2,50]]
39+
@test getindex(Cbands,1,100) == getindex(Cbands,1,1:100)[100]
4040
end
4141
end
4242

43-
@testset "Comparison with Lanczos and Classical" begin
43+
@testset "Comparison with Lanczos and Classical, non-Clenshaw" begin
4444
@testset "w(x) = x^2*(1-x)" begin
4545
P = Normalized(Legendre()[affine(0..1,Inclusion(-1..1)),:])
4646
x = axes(P,1)
@@ -106,4 +106,71 @@ end
106106
# Comparison
107107
@test Jchol[1:500,1:500] Jlanc[1:500,1:500]
108108
end
109+
end
110+
111+
@testset "Comparison with Lanczos and Classical, with Clenshaw, basics" begin
112+
@testset "w(x) = x^2*(1-x)" begin
113+
P = Normalized(Legendre()[affine(0..1,Inclusion(-1..1)),:])
114+
x = axes(P,1)
115+
J = jacobimatrix(P)
116+
Jx = symmjacobim(J)
117+
wf(x) = x^2*(1-x)
118+
# compute Jacobi matrix via cholesky
119+
W = P \ (wf.(x) .* P)
120+
Jchol = cholesky_jacobimatrix(Symmetric(W))
121+
# compute Jacobi matrix via classical recurrence
122+
Q = Normalized(Jacobi(1,2)[affine(0..1,Inclusion(-1..1)),:])
123+
Jclass = jacobimatrix(Q)
124+
# compute Jacobi matrix via Lanczos
125+
Jlanc = jacobimatrix(LanczosPolynomial(@.(wf.(x)),Normalized(Legendre()[affine(0..1,Inclusion(-1..1)),:])))
126+
# Comparison with Lanczos
127+
@test Jchol[1:500,1:500] Jlanc[1:500,1:500]
128+
# Comparison with Classical
129+
@test Jchol[1:500,1:500] Jclass[1:500,1:500]
130+
end
131+
132+
@testset "w(x) = (1-x^2)" begin
133+
P = Normalized(Legendre()[affine(0..1,Inclusion(-1..1)),:])
134+
x = axes(P,1)
135+
J = jacobimatrix(P)
136+
Jx = symmjacobim(J)
137+
wf(x) = (1-x^2)
138+
# compute Jacobi matrix via cholesky
139+
W = P \ (wf.(x) .* P)
140+
Jchol = cholesky_jacobimatrix(Symmetric(W))
141+
# compute Jacobi matrix via Lanczos
142+
Jlanc = jacobimatrix(LanczosPolynomial(@.(wf.(x)),Normalized(Legendre()[affine(0..1,Inclusion(-1..1)),:])))
143+
# Comparison with Lanczos
144+
@test Jchol[1:500,1:500] Jlanc[1:500,1:500]
145+
end
146+
147+
@testset "w(x) = (1-x^4)" begin
148+
P = Normalized(Legendre()[affine(0..1,Inclusion(-1..1)),:])
149+
x = axes(P,1)
150+
J = jacobimatrix(P)
151+
Jx = symmjacobim(J)
152+
wf(x) = (1-x^4)
153+
# compute Jacobi matrix via cholesky
154+
W = P \ (wf.(x) .* P)
155+
Jchol = cholesky_jacobimatrix(Symmetric(W))
156+
# compute Jacobi matrix via Lanczos
157+
Jlanc = jacobimatrix(LanczosPolynomial(@.(wf.(x)),Normalized(Legendre()[affine(0..1,Inclusion(-1..1)),:])))
158+
# Comparison with Lanczos
159+
@test Jchol[1:500,1:500] Jlanc[1:500,1:500]
160+
end
161+
162+
@testset "w(x) = (1.014-x^3)" begin
163+
P = Normalized(Legendre()[affine(0..1,Inclusion(-1..1)),:])
164+
x = axes(P,1)
165+
J = jacobimatrix(P)
166+
Jx = symmjacobim(J)
167+
wf(x) = 1.014-x^4
168+
# compute Jacobi matrix via cholesky
169+
W = P \ (wf.(x) .* P)
170+
Jchol = cholesky_jacobimatrix(Symmetric(W))
171+
# compute Jacobi matrix via Lanczos
172+
Jlanc = jacobimatrix(LanczosPolynomial(@.(wf.(x)),Normalized(Legendre()[affine(0..1,Inclusion(-1..1)),:])))
173+
# Comparison with Lanczos
174+
@test Jchol[1:500,1:500] Jlanc[1:500,1:500]
175+
end
109176
end

0 commit comments

Comments
 (0)