Skip to content

Commit df8f74c

Browse files
committed
Merge remote-tracking branch 'upstream/master' into SmoothedConstantInterpolation
2 parents 8df2e4f + 5f029a7 commit df8f74c

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/parameter_caches.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ end
1515

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

2121
function linear_interpolation_parameters(u::AbstractArray{T, N}, t, idx) where {T, N}

test/interpolation_tests.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using Optim, ForwardDiff
55
using BenchmarkTools
66
using Unitful
77
using LinearAlgebra
8+
using Symbolics
89

910
function test_interpolation_type(T)
1011
@test T <: DataInterpolations.AbstractInterpolation
@@ -1125,3 +1126,30 @@ end
11251126
@test_throws ArgumentError LinearInterpolation(rand(10), rand(10))
11261127
@test_throws ArgumentError LinearInterpolation(0:10, rand(10))
11271128
end
1129+
1130+
@testset "Symbolic interpolation" begin
1131+
rng = StableRNG(50225)
1132+
1133+
t = 0.01:0.01:1.00
1134+
@variables x[1:100]
1135+
1136+
ci = ConstantInterpolation(x, t)
1137+
li = LinearInterpolation(x, t)
1138+
1139+
@test isequal(ci(0.425), x[42])
1140+
@test isequal(li(0.425), x[42] + 0.5*(x[43] - x[42]))
1141+
1142+
xvals = rand(rng, 100)
1143+
@test Symbolics.substitute(ci(0.425), Dict(x => xvals)) == xvals[42]
1144+
@test Symbolics.substitute(li(0.425), Dict(x => xvals)) == xvals[42] + 0.5*(xvals[43] - xvals[42])
1145+
1146+
@variables dx[1:100]
1147+
@test_nowarn chs = CubicHermiteSpline(dx, x, t)
1148+
@test_nowarn qi = QuadraticInterpolation(x, t)
1149+
@test_nowarn li = LagrangeInterpolation(x, t)
1150+
@test_nowarn cs = CubicSpline(x, t)
1151+
1152+
@test_throws Exception ai = AkimaInterpolation(x, t)
1153+
@test_throws Exception bsi = BSplineInterpolation(x, t, 3, :ArcLen, :Average)
1154+
@test_throws Exception pc = PCHIPInterpolation(x, t)
1155+
end

0 commit comments

Comments
 (0)