Skip to content
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
2 changes: 1 addition & 1 deletion src/parameter_caches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ end

# Prevent e.g. Inf - Inf = NaN
function safe_diff(b, a::T) where {T}
b == a ? zero(T) : b - a
isequal(b, a) ? zero(T) : b - a
end

function linear_interpolation_parameters(u::AbstractArray{T, N}, t, idx) where {T, N}
Expand Down
28 changes: 28 additions & 0 deletions test/interpolation_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using Optim, ForwardDiff
using BenchmarkTools
using Unitful
using LinearAlgebra
using Symbolics

function test_interpolation_type(T)
@test T <: DataInterpolations.AbstractInterpolation
Expand Down Expand Up @@ -1110,3 +1111,30 @@ end
@test_throws ArgumentError LinearInterpolation(rand(10), rand(10))
@test_throws ArgumentError LinearInterpolation(0:10, rand(10))
end

@testset "Symbolic interpolation" begin
rng = StableRNG(50225)

t = 0.01:0.01:1.00
@variables x[1:100]

ci = ConstantInterpolation(x, t)
li = LinearInterpolation(x, t)

@test isequal(ci(0.425), x[42])
@test isequal(li(0.425), x[42] + 0.5*(x[43] - x[42]))

xvals = rand(rng, 100)
@test Symbolics.substitute(ci(0.425), Dict(x => xvals)) == xvals[42]
@test Symbolics.substitute(li(0.425), Dict(x => xvals)) == xvals[42] + 0.5*(xvals[43] - xvals[42])

@variables dx[1:100]
@test_nowarn chs = CubicHermiteSpline(dx, x, t)
@test_nowarn qi = QuadraticInterpolation(x, t)
@test_nowarn li = LagrangeInterpolation(x, t)
@test_nowarn cs = CubicSpline(x, t)

@test_throws Exception ai = AkimaInterpolation(x, t)
@test_throws Exception bsi = BSplineInterpolation(x, t, 3, :ArcLen, :Average)
@test_throws Exception pc = PCHIPInterpolation(x, t)
end
Loading