Skip to content

Commit 042cf04

Browse files
Merge pull request #383 from SciML/ChrisRackauckas-patch-2
Remove hardcoded Float64s in AkimaInterpolation
2 parents ecad6a6 + bbfa7d6 commit 042cf04

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/interpolation_caches.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,16 @@ function AkimaInterpolation(
280280
m[end - 1] = 2m[end - 2] - m[end - 3]
281281
m[end] = 2m[end - 1] - m[end - 2]
282282

283-
b = 0.5 .* (m[4:end] .+ m[1:(end - 3)])
283+
b = (m[4:end] .+ m[1:(end - 3)]) ./ 2
284284
dm = abs.(diff(m))
285285
f1 = dm[3:(n + 2)]
286286
f2 = dm[1:n]
287287
f12 = f1 + f2
288288
ind = findall(f12 .> 1e-9 * maximum(f12))
289289
b[ind] = (f1[ind] .* m[ind .+ 1] .+
290290
f2[ind] .* m[ind .+ 2]) ./ f12[ind]
291-
c = (3.0 .* m[3:(end - 2)] .- 2.0 .* b[1:(end - 1)] .- b[2:end]) ./ dt
292-
d = (b[1:(end - 1)] .+ b[2:end] .- 2.0 .* m[3:(end - 2)]) ./ dt .^ 2
291+
c = (3 .* m[3:(end - 2)] .- 2 .* b[1:(end - 1)] .- b[2:end]) ./ dt
292+
d = (b[1:(end - 1)] .+ b[2:end] .- 2 .* m[3:(end - 2)]) ./ dt .^ 2
293293

294294
A = AkimaInterpolation(
295295
u, t, nothing, b, c, d, extrapolation_left,

test/interface.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,15 @@ end
5555
@inferred QuinticHermiteSpline(ddu, du, u, t)
5656
end
5757
end
58+
59+
@testset "Output Type" begin
60+
# Test consistency between eltype(u) and type of the output
61+
u = Float32[-0.676367f0, 0.8449812f0, 1.2366607f0, -0.13347931f0, 1.9928657f0,
62+
-0.63596356f0, 0.76009744f0, -0.30632544f0, 0.34649512f0, -0.3846099f0]
63+
t = 0.1f0:0.1f0:1.0f0
64+
for extrapolation_flag in instances(ExtrapolationType.T)
65+
(extrapolation_flag == ExtrapolationType.None) && continue
66+
aki = AkimaInterpolation(u, t; extrapolation = extrapolation_flag)
67+
@test eltype(aki.([-2.0f0, 0.5f0, 3.0f0])) == Float32
68+
end
69+
end

0 commit comments

Comments
 (0)