Skip to content

Add tests for ApproxFunBase #111

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 19, 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
4 changes: 4 additions & 0 deletions test/SpeedODETest.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module SpeedODETest
using ApproxFunOrthogonalPolynomials, SpecialFunctions, Test
import ApproxFunBase: ldiv_coefficients
using LinearAlgebra

## ODEs

Expand Down Expand Up @@ -113,3 +115,5 @@ u=nullspace(A)
@test A[1:10,1:10] ≈ transpose(transpose(A)[1:10,1:10])
@time u=nullspace(A)
println("Nullspace Airy: 0.052730 seconds (75.21 k allocations: 56.736 MB)")

end # module
3 changes: 3 additions & 0 deletions test/SpeedOperatorTest.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module SpeedOperatorTest
using ApproxFunOrthogonalPolynomials, Test


Expand Down Expand Up @@ -29,3 +30,5 @@ A=Derivative(d)^2-x
#
# Profile.print()
@time a*b #0.0014

end # module
6 changes: 5 additions & 1 deletion test/SpeedPDETest.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module SpeedPDETest
using ApproxFunOrthogonalPolynomials, BlockBandedMatrices, Test
import ApproxFunOrthogonalPolynomials: Block
import ApproxFunOrthogonalPolynomials: Block
using LinearAlgebra

## PDEs
d=ChebyshevInterval()^2
Expand Down Expand Up @@ -42,3 +44,5 @@ println("Neumann Helmholtz: should be ~0.032")
# @time u=PO\u0
#
# println("Schrodinger: should be ~0.013,0.015")

end # module
5 changes: 3 additions & 2 deletions test/SpeedTest.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module SpeedTest
using ApproxFunOrthogonalPolynomials, Test


c = rand(1000)
x=rand(10000)
f=Fun(Chebyshev,c)
Expand Down Expand Up @@ -38,3 +37,5 @@ roots(f)
roots(f)
@time roots(f)
println("Roots: Time should be ~0.08")

end # module
95 changes: 79 additions & 16 deletions test/miscAFBase.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,83 @@
using ApproxFunOrthogonalPolynomials
using ApproxFunBase
@testset "ApproxFunOrthogonalPolynomials" begin
@test (@inferred Fun()) == Fun(x->x, Chebyshev())
@test (@inferred norm(Fun())) ≈ norm(Fun(), 2) ≈ √(2/3) # √∫x^2 dx over -1..1

v = rand(4)
v2 = transform(NormalizedChebyshev(), v)
@test itransform(NormalizedChebyshev(), v2) ≈ v

f = @inferred Fun(x->x^2, Chebyshev())
v = @inferred coefficients(f, Chebyshev(), Legendre())
@test eltype(v) == eltype(coefficients(f))
@test v ≈ coefficients(Fun(x->x^2, Legendre()))

# inference check for coefficients
v = @inferred coefficients(Float64[0,0,1], Chebyshev(), Ultraspherical(1))
@test v ≈ [-0.5, 0, 0.5]
using Test
using LinearAlgebra
using StaticArrays
using BandedMatrices

@testset "ApproxFunBase" begin
@testset "Constructor" begin
@test (@inferred Fun()) == Fun(x->x, Chebyshev())
@test (@inferred norm(Fun())) ≈ norm(Fun(), 2) ≈ √(2/3) # √∫x^2 dx over -1..1
end

@testset "transform" begin
v = rand(4)
v2 = transform(NormalizedChebyshev(), v)
@test itransform(NormalizedChebyshev(), v2) ≈ v

@testset "coefficients" begin
f = @inferred Fun(x->x^2, Chebyshev())
v = @inferred coefficients(f, Chebyshev(), Legendre())
@test eltype(v) == eltype(coefficients(f))
@test v ≈ coefficients(Fun(x->x^2, Legendre()))

# inference check for coefficients
v = @inferred coefficients(Float64[0,0,1], Chebyshev(), Ultraspherical(1))
@test v ≈ [-0.5, 0, 0.5]
end
end

@testset "multiplication inference" begin
function g2()
f = Fun(0..1)
f * f
end
y = @inferred g2()(0.1)
@test y ≈ (0.1)^2

function g3()
f = Fun(0..1)
f * f * f
end
y = @inferred g3()(0.1)
@test y ≈ (0.1)^3

function g4()
f = Fun(0..1)
f * f * f * f
end
y = @inferred g4()(0.1)
@test y ≈ (0.1)^4
end

@testset "intpow" begin
@testset "Interval" begin
function h(::Val{N}) where {N}
f = Fun(0..1)
f^N
end
@test (@inferred h(Val(0)))(0.1) ≈ (0.1)^0
@test (@inferred h(Val(1)))(0.1) ≈ (0.1)^1
@test (@inferred h(Val(2)))(0.1) ≈ (0.1)^2
@test (@inferred h(Val(3)))(0.1) ≈ (0.1)^3
@test (@inferred h(Val(4)))(0.1) ≈ (0.1)^4
@test h(Val(10))(0.1) ≈ (0.1)^10 rtol=1e-6
end

@testset "ChebyshevInterval" begin
function h(::Val{N}) where {N}
f = Fun()
f^N
end
@test (@inferred h(Val(0)))(0.1) ≈ (0.1)^0
@test (@inferred h(Val(1)))(0.1) ≈ (0.1)^1
@test (@inferred h(Val(2)))(0.1) ≈ (0.1)^2
@test (@inferred h(Val(3)))(0.1) ≈ (0.1)^3
@test (@inferred h(Val(4)))(0.1) ≈ (0.1)^4
@test h(Val(10))(0.1) ≈ (0.1)^10 rtol=1e-6
end
end

@testset "int coeffs" begin
f = Fun(Chebyshev(), [0,1])
Expand Down