Skip to content

Test for nD transforms #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions test/ChebyshevTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,27 @@ import ApproxFunOrthogonalPolynomials: forwardrecurrence
end

@testset "inplace transform" begin
for T in [Float32, Float64, BigFloat]
for v in Any[rand(T, 10), rand(complex(T), 10)]
v2 = copy(v)
transform!(Chebyshev(), v)
@test transform(Chebyshev(), v2) == v
itransform!(Chebyshev(), v)
@test v2 ≈ v
@testset for T in [Float32, Float64], ET in Any[T, complex(T)]
v = Array{ET}(undef, 10)
v2 = similar(v)
M = Array{ET}(undef, 10, 10)
M2 = similar(M)
A = Array{ET}(undef, 10, 10, 10)
A2 = similar(A)
@testset for d in Any[(), (0..1,)]
C = Chebyshev(d...)
Slist = Any[C, NormalizedPolynomialSpace(C)]
@testset for S in Slist
test_transform!(v, v2, S)
end
@testset for S1 in Slist, S2 in Slist
S = S1 ⊗ S2
test_transform!(M, M2, S)
end
@testset for S1 in Slist, S2 in Slist, S3 in Slist
S = S1 ⊗ S2 ⊗ S3
test_transform!(A, A2, S)
end
end
end
end
Expand Down Expand Up @@ -271,4 +285,14 @@ import ApproxFunOrthogonalPolynomials: forwardrecurrence
@test M^10 == foldr(*, fill(M, 10))
end
end

@testset "values for ArraySpace Fun" begin
f = Fun(Chebyshev() ⊗ Chebyshev())
@test f.(points(f)) == points(f)
@test values(f) == itransform(space(f), coefficients(f))
a = transform(space(f), values(f))
b = coefficients(f)
nmin = min(length(a), length(b))
@test a[1:nmin] ≈ b[1:nmin]
end
end
39 changes: 30 additions & 9 deletions test/JacobiTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,36 @@ import ApproxFunOrthogonalPolynomials: jacobip
@test norm(Fun(Fun(exp),Jacobi(-.5,-.5))-Fun(exp,Jacobi(-.5,-.5))) < 300eps()

@testset "inplace transform" begin
for T in [Float32, Float64, BigFloat]
for v in Any[rand(T, 10), rand(complex(T), 10)]
v2 = copy(v)
for a in 0:0.5:3, b in 0:0.5:3
J = Jacobi(a, b)
transform!(J, v)
@test transform(J, v2) ≈ v
itransform!(J, v)
@test v2 ≈ v
@testset for T in [Float32, Float64], ET in Any[T, complex(T)]
v = Array{ET}(undef, 10)
v2 = similar(v)
@testset for a in 0:0.5:3, b in 0:0.5:3, d in Any[(), (0..1,)]
J = Jacobi(a, b, d...)
Slist = Any[J, NormalizedPolynomialSpace(J)]
@testset for S in Slist
test_transform!(v, v2, S)
end
end
v = Array{ET}(undef, 10, 10)
v2 = similar(v)
@testset for a in 0:0.5:3, b in 0:0.5:3, d in Any[(), (0..1,)]
J = Jacobi(a, b, d...)
Slist = Any[J, NormalizedPolynomialSpace(J)]
@testset for S1 in Slist, S2 in Slist
S = S1 ⊗ S2
test_transform!(v, v2, S)
end
@testset for S1 in Slist
S = S1 ⊗ Chebyshev(d...)
test_transform!(v, v2, S)
S = S1 ⊗ Chebyshev()
test_transform!(v, v2, S)
end
@testset for S2 in Slist
S = Chebyshev(d...) ⊗ S2
test_transform!(v, v2, S)
S = Chebyshev() ⊗ S2
test_transform!(v, v2, S)
end
end
end
Expand Down
54 changes: 42 additions & 12 deletions test/UltrasphericalTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,50 @@ import ApproxFunOrthogonalPolynomials: jacobip
end

@testset "inplace transform" begin
@testset for T in [Float32, Float64, ComplexF32, ComplexF64]
v = rand(T, 4)
vc = copy(v)
function ultra2leg(U::Ultraspherical)
@assert ApproxFunOrthogonalPolynomials.order(U) == 0.5
Legendre(domain(U))
end
function ultra2leg(U::NormalizedPolynomialSpace{<:Ultraspherical})
L = ultra2leg(ApproxFunBase.canonicalspace(U))
NormalizedPolynomialSpace(L)
end
@testset for T in Any[Float32, Float64], ET in Any[T, complex(T)]
v = Array{ET}(undef, 10)
v2 = similar(v)
M = Array{ET}(undef, 10, 10)
M2 = similar(M)
A = Array{ET}(undef, 10, 10, 10)
A2 = similar(A)
@testset for d in Any[(), (0..1,)], order in Any[0.5, 1, 3]
S = Ultraspherical(order, d...)
v2 = transform(S, v)
if order == 0.5
@test v2 ≈ transform(Legendre(domain(S)), v)
U = Ultraspherical(order, d...)
Slist = Any[U, NormalizedPolynomialSpace(U)]
@testset for S in Slist
if order == 0.5
L = ultra2leg(S)
v .= rand.(eltype(v))
@test transform(S, v) ≈ transform(L, v)
end
test_transform!(v, v2, S)
end
@testset for S1 in Slist, S2 in Slist
S = S1 ⊗ S2
if order == 0.5
L = ultra2leg(S1) ⊗ ultra2leg(S2)
M .= rand.(eltype(M))
@test transform(S, M) ≈ transform(L, M)
end
test_transform!(M, M2, S)
end
@testset for S1 in Slist, S2 in Slist, S3 in Slist
S = S1 ⊗ S2 ⊗ S3
if order == 0.5
L = ultra2leg(S1) ⊗ ultra2leg(S2) ⊗ ultra2leg(S3)
A .= rand.(eltype(A))
@test transform(S, A) ≈ transform(L, A)
end
test_transform!(A, A2, S)
end
transform!(S, v)
@test v ≈ v2
itransform!(S, v)
@test v ≈ vc
@test v ≈ itransform(S, v2)
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ end
@test reverseorientation(Arc(1,2,(0.1,0.2))) == Arc(1,2,(0.2,0.1))
end

function test_transform!(v, v2, S)
v .= rand.(eltype(v))
v2 .= v
@test itransform(S, transform(S, v)) ≈ v
@test transform(S, itransform(S, v)) ≈ v
transform!(S, v)
@test transform(S, v2) ≈ v
itransform!(S, v)
@test v2 ≈ v
end

include("ClenshawTest.jl")
include("ChebyshevTest.jl")
include("ComplexTest.jl")
Expand Down