Skip to content

Commit 5260921

Browse files
reinstate tests
1 parent 0c5cc86 commit 5260921

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FastTransforms"
22
uuid = "057dd010-8810-581a-b7be-e3fc3b93f78c"
3-
version = "0.16.7"
3+
version = "0.16.8"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

test/grammatrixtests.jl

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using FastTransforms, BandedMatrices, LazyArrays, LinearAlgebra, Test
2+
3+
@testset "GramMatrix" begin
4+
n = 128
5+
for T in (Float32, Float64, BigFloat)
6+
R = plan_leg2cheb(T, n; normcheb=true)*I
7+
X = Tridiagonal([T(n)/(2n-1) for n in 1:n-1], zeros(T, n), [T(n)/(2n+1) for n in 1:n-1]) # Legendre X
8+
W = Symmetric(R'R)
9+
G = GramMatrix(W, X)
10+
F = cholesky(G)
11+
@test F.L*F.L' W
12+
@test F.U R
13+
14+
R = plan_leg2cheb(T, n; normcheb=true, normleg=true)*I
15+
X = SymTridiagonal(zeros(T, n), [sqrt(T(n)^2/(4*n^2-1)) for n in 1:n-1]) # normalized Legendre X
16+
W = Symmetric(R'R)
17+
G = GramMatrix(W, X)
18+
F = cholesky(G)
19+
@test F.L*F.L' W
20+
@test F.U R
21+
22+
b = 4
23+
X = BandedMatrix(SymTridiagonal(zeros(T, n+b), [sqrt(T(n)^2/(4*n^2-1)) for n in 1:n+b-1])) # normalized Legendre X
24+
W = I+X^2+X^4
25+
W = Symmetric(W[1:n, 1:n])
26+
X = BandedMatrix(SymTridiagonal(zeros(T, n), [sqrt(T(n)^2/(4*n^2-1)) for n in 1:n-1])) # normalized Legendre X
27+
G = GramMatrix(W, X)
28+
@test bandwidths(G) == (b, b)
29+
F = cholesky(G)
30+
@test F.L*F.L' W
31+
32+
X = BandedMatrix(SymTridiagonal(T[2n-1 for n in 1:n+b], T[-n for n in 1:n+b-1])) # Laguerre X, tests nonzero diagonal
33+
W = I+X^2+X^4
34+
W = Symmetric(W[1:n, 1:n])
35+
X = BandedMatrix(SymTridiagonal(T[2n-1 for n in 1:n], T[-n for n in 1:n-1])) # Laguerre X
36+
G = GramMatrix(W, X)
37+
@test bandwidths(G) == (b, b)
38+
F = cholesky(G)
39+
@test F.L*F.L' W
40+
end
41+
W = reshape([i for i in 1.0:n^2], n, n)
42+
X = reshape([i for i in 1.0:4n^2], 2n, 2n)
43+
@test_throws "different sizes" GramMatrix(W, X)
44+
X = X[1:n, 1:n]
45+
@test_throws "nonsymmetric" GramMatrix(W, X)
46+
@test_throws "nontridiagonal" GramMatrix(Symmetric(W), X)
47+
end
48+
49+
@testset "ChebyshevGramMatrix" begin
50+
n = 128
51+
for T in (Float32, Float64, BigFloat)
52+
μ = FastTransforms.chebyshevmoments1(T, 2n-1)
53+
G = ChebyshevGramMatrix(μ)
54+
F = cholesky(G)
55+
@test F.L*F.L' G
56+
R = plan_cheb2leg(T, n; normleg=true)*I
57+
@test F.U R
58+
59+
α, β = (T(0.123), T(0.456))
60+
μ = FastTransforms.chebyshevjacobimoments1(T, 2n-1, α, β)
61+
G = ChebyshevGramMatrix(μ)
62+
F = cholesky(G)
63+
@test F.L*F.L' G
64+
R = plan_cheb2jac(T, n, α, β; normjac=true)*I
65+
@test F.U R
66+
67+
μ = -FastTransforms.chebyshevlogmoments1(T, 2n-1)
68+
G = ChebyshevGramMatrix(μ)
69+
F = cholesky(G)
70+
@test F.L*F.L' G
71+
72+
μ = FastTransforms.chebyshevabsmoments1(T, 2n-1)
73+
G = ChebyshevGramMatrix(μ)
74+
F = cholesky(G)
75+
@test F.L*F.L' G
76+
77+
μ = PaddedVector(T(1) ./ [1,2,3,4,5], 2n-1)
78+
G = ChebyshevGramMatrix(μ)
79+
@test bandwidths(G) == (4, 4)
80+
F = cholesky(G)
81+
@test F.L*F.L' G
82+
μd = Vector{T}(μ)
83+
Gd = ChebyshevGramMatrix(μd)
84+
Fd = cholesky(Gd)
85+
@test F.L Fd.L
86+
end
87+
end

0 commit comments

Comments
 (0)