Skip to content

Commit

Permalink
Merge pull request #383 from SciML/ChrisRackauckas-patch-2
Browse files Browse the repository at this point in the history
Remove hardcoded Float64s in AkimaInterpolation
  • Loading branch information
ChrisRackauckas authored Jan 31, 2025
2 parents ecad6a6 + bbfa7d6 commit 042cf04
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/interpolation_caches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,16 @@ function AkimaInterpolation(
m[end - 1] = 2m[end - 2] - m[end - 3]
m[end] = 2m[end - 1] - m[end - 2]

b = 0.5 .* (m[4:end] .+ m[1:(end - 3)])
b = (m[4:end] .+ m[1:(end - 3)]) ./ 2
dm = abs.(diff(m))
f1 = dm[3:(n + 2)]
f2 = dm[1:n]
f12 = f1 + f2
ind = findall(f12 .> 1e-9 * maximum(f12))
b[ind] = (f1[ind] .* m[ind .+ 1] .+
f2[ind] .* m[ind .+ 2]) ./ f12[ind]
c = (3.0 .* m[3:(end - 2)] .- 2.0 .* b[1:(end - 1)] .- b[2:end]) ./ dt
d = (b[1:(end - 1)] .+ b[2:end] .- 2.0 .* m[3:(end - 2)]) ./ dt .^ 2
c = (3 .* m[3:(end - 2)] .- 2 .* b[1:(end - 1)] .- b[2:end]) ./ dt
d = (b[1:(end - 1)] .+ b[2:end] .- 2 .* m[3:(end - 2)]) ./ dt .^ 2

A = AkimaInterpolation(
u, t, nothing, b, c, d, extrapolation_left,
Expand Down
12 changes: 12 additions & 0 deletions test/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ end
@inferred QuinticHermiteSpline(ddu, du, u, t)
end
end

@testset "Output Type" begin
# Test consistency between eltype(u) and type of the output
u = Float32[-0.676367f0, 0.8449812f0, 1.2366607f0, -0.13347931f0, 1.9928657f0,
-0.63596356f0, 0.76009744f0, -0.30632544f0, 0.34649512f0, -0.3846099f0]
t = 0.1f0:0.1f0:1.0f0
for extrapolation_flag in instances(ExtrapolationType.T)
(extrapolation_flag == ExtrapolationType.None) && continue
aki = AkimaInterpolation(u, t; extrapolation = extrapolation_flag)
@test eltype(aki.([-2.0f0, 0.5f0, 3.0f0])) == Float32
end
end

0 comments on commit 042cf04

Please sign in to comment.