Skip to content

Commit

Permalink
Merge pull request #230 from SciML/jac
Browse files Browse the repository at this point in the history
Promote element type for ForwardDiff jacobians
  • Loading branch information
ChrisRackauckas authored Mar 3, 2024
2 parents d121990 + 29256d3 commit 8d9baeb
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)
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 8d9baeb

Please sign in to comment.