@@ -4,120 +4,34 @@ import LazyArrays: AbstractCachedMatrix
4
4
import LazyBandedMatrices: SymTridiagonal
5
5
6
6
@testset " Basic properties" begin
7
- @testset " Test the Q&D conversion to BandedMatrix format" begin
8
- # Legendre
9
- P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
10
- x = axes (P,1 )
11
- J = jacobimatrix (P)
12
- Jx = symmjacobim (J)
13
- @test J[1 : 100 ,1 : 100 ] == Jx[1 : 100 ,1 : 100 ]
14
- # Jacobi
15
- P = Normalized (Jacobi (1 ,2 )[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
16
- x = axes (P,1 )
17
- J = jacobimatrix (P)
18
- Jx = symmjacobim (J)
19
- @test J[1 : 100 ,1 : 100 ] == Jx[1 : 100 ,1 : 100 ]
20
- end
21
-
22
- @testset " Basic types and getindex variants" begin
23
- # basis
24
- P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
25
- x = axes (P,1 )
26
- J = jacobimatrix (P)
27
- Jx = symmjacobim (J)
28
- # example weight
29
- w = (I - Jx^ 2 )
30
- # banded cholesky for symmetric-tagged W
31
- @test cholesky (w). U isa UpperTriangular
32
- # compute Jacobi matrix via cholesky
33
- Jchol = cholesky_jacobimatrix (w)
34
- @test Jchol isa LazyBandedMatrices. SymTridiagonal
35
- # CholeskyJacobiBands object
36
- Cbands = CholeskyJacobiBands (w)
37
- @test Cbands isa CholeskyJacobiBands
38
- @test Cbands isa AbstractCachedMatrix
39
- @test getindex (Cbands,1 ,100 ) == getindex (Cbands,1 ,1 : 100 )[100 ]
40
- end
7
+ # basis
8
+ P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
9
+ x = axes (P,1 )
10
+ J = jacobimatrix (P)
11
+ # example weight
12
+ w (x) = (1 - x^ 2 )
13
+ W = Symmetric (P \ (w .(x) .* P))
14
+ # banded cholesky for symmetric-tagged W
15
+ @test cholesky (W). U isa UpperTriangular
16
+ # compute Jacobi matrix via cholesky
17
+ Jchol = cholesky_jacobimatrix (w,P)
18
+ @test Jchol isa SymTridiagonal
19
+ # CholeskyJacobiBands object
20
+ Cbands = CholeskyJacobiBands (W,P)
21
+ @test Cbands isa CholeskyJacobiBands
22
+ @test Cbands isa AbstractCachedMatrix
23
+ @test getindex (Cbands,1 ,100 ) == getindex (Cbands,1 ,1 : 100 )[100 ]
41
24
end
42
25
43
26
@testset " Comparison with Lanczos and Classical" begin
44
- @testset " Not using Clenshaw" begin
45
- @testset " w(x) = x^2*(1-x)" begin
46
- P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
47
- x = axes (P,1 )
48
- J = jacobimatrix (P)
49
- Jx = symmjacobim (J)
50
- w = (Jx^ 2 - Jx^ 3 )
51
- # compute Jacobi matrix via cholesky
52
- Jchol = cholesky_jacobimatrix (w)
53
- # compute Jacobi matrix via classical recurrence
54
- Q = Normalized (Jacobi (1 ,2 )[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
55
- Jclass = jacobimatrix (Q)
56
- # compute Jacobi matrix via Lanczos
57
- wf = x.^ 2 .* (1 .- x)
58
- Jlanc = jacobimatrix (LanczosPolynomial (@. (wf),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
59
- # Comparison with Lanczos
60
- @test Jchol[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
61
- # Comparison with Classical
62
- @test Jchol[1 : 500 ,1 : 500 ] ≈ Jclass[1 : 500 ,1 : 500 ]
63
- end
64
-
65
- @testset " w(x) = (1-x^2)" begin
66
- P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
67
- x = axes (P,1 )
68
- J = jacobimatrix (P)
69
- Jx = symmjacobim (J)
70
- w = (I - Jx^ 2 )
71
- # compute Jacobi matrix via cholesky
72
- Jchol = cholesky_jacobimatrix (w)
73
- # compute Jacobi matrix via Lanczos
74
- wf = (1 .- x.^ 2 )
75
- Jlanc = jacobimatrix (LanczosPolynomial (@. (wf),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
76
- # Comparison
77
- @test Jchol[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
78
- end
79
-
80
- @testset " w(x) = (1-x^4)" begin
81
- P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
82
- x = axes (P,1 )
83
- J = jacobimatrix (P)
84
- Jx = symmjacobim (J)
85
- w = (I - Jx^ 4 )
86
- # compute Jacobi matrix via cholesky
87
- Jchol = cholesky_jacobimatrix (w)
88
- # compute Jacobi matrix via Lanczos
89
- wf = (1 .- x.^ 4 )
90
- Jlanc = jacobimatrix (LanczosPolynomial (@. (wf),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
91
- # Comparison
92
- @test Jchol[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
93
- end
94
-
95
- @testset " w(x) = (1.014-x^3)" begin
96
- P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
97
- x = axes (P,1 )
98
- J = jacobimatrix (P)
99
- Jx = symmjacobim (J)
100
- t = 1.014
101
- w = (t* I - Jx^ 3 )
102
- # compute Jacobi matrix via cholesky
103
- Jchol = cholesky_jacobimatrix (w)
104
- # compute Jacobi matrix via Lanczos
105
- wf = (t .- x.^ 3 )
106
- Jlanc = jacobimatrix (LanczosPolynomial (@. (wf),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
107
- # Comparison
108
- @test Jchol[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
109
- end
110
- end
111
-
112
27
@testset " Using Clenshaw for polynomial weights" begin
113
28
@testset " w(x) = x^2*(1-x)" begin
114
29
P = Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
115
30
x = axes (P,1 )
116
31
J = jacobimatrix (P)
117
32
wf (x) = x^ 2 * (1 - x)
118
33
# compute Jacobi matrix via cholesky
119
- W = P \ (wf .(x) .* P)
120
- Jchol = cholesky_jacobimatrix (Symmetric (W))
34
+ Jchol = cholesky_jacobimatrix (wf, P)
121
35
# compute Jacobi matrix via classical recurrence
122
36
Q = Normalized (Jacobi (1 ,2 )[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])
123
37
Jclass = jacobimatrix (Q)
135
49
J = jacobimatrix (P)
136
50
wf (x) = (1 - x^ 2 )
137
51
# compute Jacobi matrix via cholesky
138
- W = P \ (wf .(x) .* P)
139
- Jchol = cholesky_jacobimatrix (Symmetric (W))
52
+ Jchol = cholesky_jacobimatrix (wf, P)
140
53
# compute Jacobi matrix via Lanczos
141
54
Jlanc = jacobimatrix (LanczosPolynomial (@. (wf .(x)),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
142
55
# Comparison with Lanczos
149
62
J = jacobimatrix (P)
150
63
wf (x) = (1 - x^ 4 )
151
64
# compute Jacobi matrix via cholesky
152
- W = P \ (wf .(x) .* P)
153
- Jchol = cholesky_jacobimatrix (Symmetric (W))
65
+ Jchol = cholesky_jacobimatrix (wf, P)
154
66
# compute Jacobi matrix via Lanczos
155
67
Jlanc = jacobimatrix (LanczosPolynomial (@. (wf .(x)),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
156
68
# Comparison with Lanczos
163
75
J = jacobimatrix (P)
164
76
wf (x) = 1.014 - x^ 4
165
77
# compute Jacobi matrix via cholesky
166
- W = P \ (wf .(x) .* P)
167
- Jchol = cholesky_jacobimatrix (Symmetric (W))
78
+ Jchol = cholesky_jacobimatrix (wf, P)
168
79
# compute Jacobi matrix via Lanczos
169
80
Jlanc = jacobimatrix (LanczosPolynomial (@. (wf .(x)),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
170
81
# Comparison with Lanczos
179
90
J = jacobimatrix (P)
180
91
wf (x) = exp (x)
181
92
# compute Jacobi matrix via cholesky
182
- W = P \ (wf .(x) .* P)
183
- Jchol = cholesky_jacobimatrix (Symmetric (W))
93
+ Jchol = cholesky_jacobimatrix (wf, P)
184
94
# compute Jacobi matrix via Lanczos
185
95
Jlanc = jacobimatrix (LanczosPolynomial (@. (wf .(x)),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
186
96
# Comparison with Lanczos
193
103
J = jacobimatrix (P)
194
104
wf (x) = (1 - x)* exp (x)
195
105
# compute Jacobi matrix via cholesky
196
- W = P \ (wf .(x) .* P)
197
- Jchol = cholesky_jacobimatrix (Symmetric (W))
106
+ Jchol = cholesky_jacobimatrix (wf, P)
198
107
# compute Jacobi matrix via Lanczos
199
108
Jlanc = jacobimatrix (LanczosPolynomial (@. (wf .(x)),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
200
109
# Comparison with Lanczos
207
116
J = jacobimatrix (P)
208
117
wf (x) = (1 - x^ 2 )* exp (x^ 2 )
209
118
# compute Jacobi matrix via cholesky
210
- W = P \ (wf .(x) .* P)
211
- Jchol = cholesky_jacobimatrix (Symmetric (W))
119
+ Jchol = cholesky_jacobimatrix (wf, P)
212
120
# compute Jacobi matrix via Lanczos
213
121
Jlanc = jacobimatrix (LanczosPolynomial (@. (wf .(x)),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
214
122
# Comparison with Lanczos
@@ -221,12 +129,11 @@ end
221
129
J = jacobimatrix (P)
222
130
wf (x) = x* (1 - x^ 2 )* exp (- x^ 2 )
223
131
# compute Jacobi matrix via cholesky
224
- W = P \ (wf .(x) .* P)
225
- Jchol = cholesky_jacobimatrix (Symmetric (W))
132
+ Jchol = cholesky_jacobimatrix (wf, P)
226
133
# compute Jacobi matrix via Lanczos
227
134
Jlanc = jacobimatrix (LanczosPolynomial (@. (wf .(x)),Normalized (Legendre ()[affine (0 .. 1 ,Inclusion (- 1 .. 1 )),:])))
228
135
# Comparison with Lanczos
229
136
@test Jchol[1 : 500 ,1 : 500 ] ≈ Jlanc[1 : 500 ,1 : 500 ]
230
137
end
231
138
end
232
- end
139
+ end
0 commit comments