Skip to content

Commit b4774a6

Browse files
authored
Test for nD transforms (#117)
1 parent e0c2fd9 commit b4774a6

File tree

4 files changed

+114
-28
lines changed

4 files changed

+114
-28
lines changed

test/ChebyshevTest.jl

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,27 @@ import ApproxFunOrthogonalPolynomials: forwardrecurrence
212212
end
213213

214214
@testset "inplace transform" begin
215-
for T in [Float32, Float64, BigFloat]
216-
for v in Any[rand(T, 10), rand(complex(T), 10)]
217-
v2 = copy(v)
218-
transform!(Chebyshev(), v)
219-
@test transform(Chebyshev(), v2) == v
220-
itransform!(Chebyshev(), v)
221-
@test v2 v
215+
@testset for T in [Float32, Float64], ET in Any[T, complex(T)]
216+
v = Array{ET}(undef, 10)
217+
v2 = similar(v)
218+
M = Array{ET}(undef, 10, 10)
219+
M2 = similar(M)
220+
A = Array{ET}(undef, 10, 10, 10)
221+
A2 = similar(A)
222+
@testset for d in Any[(), (0..1,)]
223+
C = Chebyshev(d...)
224+
Slist = Any[C, NormalizedPolynomialSpace(C)]
225+
@testset for S in Slist
226+
test_transform!(v, v2, S)
227+
end
228+
@testset for S1 in Slist, S2 in Slist
229+
S = S1 S2
230+
test_transform!(M, M2, S)
231+
end
232+
@testset for S1 in Slist, S2 in Slist, S3 in Slist
233+
S = S1 S2 S3
234+
test_transform!(A, A2, S)
235+
end
222236
end
223237
end
224238
end
@@ -274,4 +288,14 @@ import ApproxFunOrthogonalPolynomials: forwardrecurrence
274288
@test M^10 == foldr(*, fill(M, 10))
275289
end
276290
end
291+
292+
@testset "values for ArraySpace Fun" begin
293+
f = Fun(Chebyshev() Chebyshev())
294+
@test f.(points(f)) == points(f)
295+
@test values(f) == itransform(space(f), coefficients(f))
296+
a = transform(space(f), values(f))
297+
b = coefficients(f)
298+
nmin = min(length(a), length(b))
299+
@test a[1:nmin] b[1:nmin]
300+
end
277301
end

test/JacobiTest.jl

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,36 @@ import ApproxFunOrthogonalPolynomials: jacobip
4242
@test norm(Fun(Fun(exp),Jacobi(-.5,-.5))-Fun(exp,Jacobi(-.5,-.5))) < 300eps()
4343

4444
@testset "inplace transform" begin
45-
for T in [Float32, Float64, BigFloat]
46-
for v in Any[rand(T, 10), rand(complex(T), 10)]
47-
v2 = copy(v)
48-
for a in 0:0.5:3, b in 0:0.5:3
49-
J = Jacobi(a, b)
50-
transform!(J, v)
51-
@test transform(J, v2) v
52-
itransform!(J, v)
53-
@test v2 v
45+
@testset for T in [Float32, Float64], ET in Any[T, complex(T)]
46+
v = Array{ET}(undef, 10)
47+
v2 = similar(v)
48+
@testset for a in 0:0.5:3, b in 0:0.5:3, d in Any[(), (0..1,)]
49+
J = Jacobi(a, b, d...)
50+
Slist = Any[J, NormalizedPolynomialSpace(J)]
51+
@testset for S in Slist
52+
test_transform!(v, v2, S)
53+
end
54+
end
55+
v = Array{ET}(undef, 10, 10)
56+
v2 = similar(v)
57+
@testset for a in 0:0.5:3, b in 0:0.5:3, d in Any[(), (0..1,)]
58+
J = Jacobi(a, b, d...)
59+
Slist = Any[J, NormalizedPolynomialSpace(J)]
60+
@testset for S1 in Slist, S2 in Slist
61+
S = S1 S2
62+
test_transform!(v, v2, S)
63+
end
64+
@testset for S1 in Slist
65+
S = S1 Chebyshev(d...)
66+
test_transform!(v, v2, S)
67+
S = S1 Chebyshev()
68+
test_transform!(v, v2, S)
69+
end
70+
@testset for S2 in Slist
71+
S = Chebyshev(d...) S2
72+
test_transform!(v, v2, S)
73+
S = Chebyshev() S2
74+
test_transform!(v, v2, S)
5475
end
5576
end
5677
end

test/UltrasphericalTest.jl

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,50 @@ import ApproxFunOrthogonalPolynomials: jacobip
5151
end
5252

5353
@testset "inplace transform" begin
54-
@testset for T in [Float32, Float64, ComplexF32, ComplexF64]
55-
v = rand(T, 4)
56-
vc = copy(v)
54+
function ultra2leg(U::Ultraspherical)
55+
@assert ApproxFunOrthogonalPolynomials.order(U) == 0.5
56+
Legendre(domain(U))
57+
end
58+
function ultra2leg(U::NormalizedPolynomialSpace{<:Ultraspherical})
59+
L = ultra2leg(ApproxFunBase.canonicalspace(U))
60+
NormalizedPolynomialSpace(L)
61+
end
62+
@testset for T in Any[Float32, Float64], ET in Any[T, complex(T)]
63+
v = Array{ET}(undef, 10)
64+
v2 = similar(v)
65+
M = Array{ET}(undef, 10, 10)
66+
M2 = similar(M)
67+
A = Array{ET}(undef, 10, 10, 10)
68+
A2 = similar(A)
5769
@testset for d in Any[(), (0..1,)], order in Any[0.5, 1, 3]
58-
S = Ultraspherical(order, d...)
59-
v2 = transform(S, v)
60-
if order == 0.5
61-
@test v2 transform(Legendre(domain(S)), v)
70+
U = Ultraspherical(order, d...)
71+
Slist = Any[U, NormalizedPolynomialSpace(U)]
72+
@testset for S in Slist
73+
if order == 0.5
74+
L = ultra2leg(S)
75+
v .= rand.(eltype(v))
76+
@test transform(S, v) transform(L, v)
77+
end
78+
test_transform!(v, v2, S)
79+
end
80+
@testset for S1 in Slist, S2 in Slist
81+
S = S1 S2
82+
if order == 0.5
83+
L = ultra2leg(S1) ultra2leg(S2)
84+
M .= rand.(eltype(M))
85+
@test transform(S, M) transform(L, M)
86+
end
87+
test_transform!(M, M2, S)
88+
end
89+
@testset for S1 in Slist, S2 in Slist, S3 in Slist
90+
S = S1 S2 S3
91+
if order == 0.5
92+
L = ultra2leg(S1) ultra2leg(S2) ultra2leg(S3)
93+
A .= rand.(eltype(A))
94+
@test transform(S, A) transform(L, A)
95+
end
96+
test_transform!(A, A2, S)
6297
end
63-
transform!(S, v)
64-
@test v v2
65-
itransform!(S, v)
66-
@test v vc
67-
@test v itransform(S, v2)
6898
end
6999
end
70100
end

test/runtests.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ end
99
@test reverseorientation(Arc(1,2,(0.1,0.2))) == Arc(1,2,(0.2,0.1))
1010
end
1111

12+
function test_transform!(v, v2, S)
13+
v .= rand.(eltype(v))
14+
v2 .= v
15+
@test itransform(S, transform(S, v)) v
16+
@test transform(S, itransform(S, v)) v
17+
transform!(S, v)
18+
@test transform(S, v2) v
19+
itransform!(S, v)
20+
@test v2 v
21+
end
22+
1223
include("ClenshawTest.jl")
1324
include("ChebyshevTest.jl")
1425
include("ComplexTest.jl")

0 commit comments

Comments
 (0)