Skip to content

Comparison with BasicInterpolators.jl #5

@markmbaum

Description

@markmbaum

Hello hello, I'm opening the issue requested here.

I've been working on 1D and 2D Chebyshev interpolators in BasicInterpolators.jl. My code does not generalize to N-dimensions like this project. It appears to be faster, though. Here are the benchmarking code and resulting plots:

using BasicInterpolators, FastChebInterp, BenchmarkTools, Statistics, Plots

##

#numbers of points to test
N = 4:2:32
#timing results
t = zeros(length(N),2) #timing for BasicInterpolators
u = zeros(length(N),2) #timing for FastChebInterp
#test coordinates
xx = rand(1000)
pts = [rand(2) for i ∈ 1:1000]

#one dimensional cases
for (i,n) ∈ enumerate(N)

    #BasicInterpolators 1D
    p = ChebyshevInterpolator(sin, 0.0, 1.0, n)
    b = @benchmark map(x -> $p(x), $xx)
    t[i,1] = mean(b.times)

    #FastChebInterp 1D
    x = chebpoints(n-1, 0, 1)
    q = chebfit(sin.(x), 0.0, 1.0, tol=0.0)
    b = @benchmark map(x -> $q(x), $xx)
    u[i,1] = mean(b.times)

    #BasicInterpolators 2D
    P = BichebyshevInterpolator((x,y)->sin(x)*cos(y), 0, 1, n, 0, 1, n)
    b = @benchmark map(x -> $P.(x,x), $xx)
    t[i,2] = mean(b.times)

    #FastChebInterp 1D
    x = chebpoints(n-1, 0, 1)
    X = x' .* ones(n)
    Y = ones(n)' .* x
    Q = chebfit(sin.(X).*cos.(Y), [0.0,0.0], [1.0,1.0])
    b = @benchmark map(pt -> $Q(pt), $pts)
    u[i,2] = mean(b.times)
end

##

p₁ = plot(N, t[:,1]*1e-6,
    label="BasicInterpolators",
    xlabel="Number of Points",
    ylabel="Time per 1000 interpolations (μs)",
    title="One Dimension")
plot!(p₁, N, u[:,1]*1e-6, label="FastChebInterp")
#savefig(p, "one_dimension")

p₂ = plot(N, t[:,2]*1e-6,
    label="BasicInterpolators",
    xlabel="Number of Points",
    ylabel="Time per 1000 interpolations (μs)",
    title="Two Dimensions")
plot!(p₂, N, u[:,2]*1e-6, label="FastChebInterp")
#savefig(p, "two_dimensions")

one_dimension
two_dimensions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions