Skip to content

Commit

Permalink
Promote element type for ForwardDiff jacobians
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Mar 3, 2024
1 parent d121990 commit 29256d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DataInterpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ include("show.jl")

(interp::AbstractInterpolation)(t::Number) = _interpolate(interp, t)
(interp::AbstractInterpolation)(t::Number, i::Integer) = _interpolate(interp, t, i)
(interp::AbstractInterpolation)(t::AbstractVector) = interp(similar(t, eltype(interp)), t)
(interp::AbstractInterpolation)(t::AbstractVector) = interp(similar(t, promote_type(eltype(interp), eltype(t))), t)

Check warning on line 32 in src/DataInterpolations.jl

View check run for this annotation

Codecov / codecov/patch

src/DataInterpolations.jl#L32

Added line #L32 was not covered by tests
function (interp::AbstractInterpolation)(u::AbstractVector, t::AbstractVector)
iguess = firstindex(interp.t)
@inbounds for i in eachindex(u, t)
Expand Down
12 changes: 12 additions & 0 deletions test/derivative_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,15 @@ end
ts = 0.0:0.1:1.0
@test all(map(ti -> symfunc(ti) == derivative(f, ti), ts))
end

@testset "Jacobian tests" begin
u = rand(5)
t = 0:4
interp = LinearInterpolation(u, t,extrapolate=true)
grad1 = ForwardDiff.derivative(interp,2.4)

myvec = rand(20).*4.0
interp(myvec)

grad = ForwardDiff.jacobian(interp,myvec)
end

0 comments on commit 29256d3

Please sign in to comment.