Skip to content

Commit

Permalink
Merge pull request #1059 from SciML/nested_sol
Browse files Browse the repository at this point in the history
Fix solutions nested in structs for forwarddiff
  • Loading branch information
ChrisRackauckas authored Jun 16, 2024
2 parents ffe1600 + 4f0c45d commit cdbe856
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/forwarddiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ function anyeltypedual(x::Type{T},
ForwardDiff.AbstractConfig}
Any
end

function anyeltypedual(::Type{<:AbstractTimeseriesSolution{T, N}},
::Type{Val{counter}} = Val{0}) where {T, N, counter}
anyeltypedual(T)
end

function anyeltypedual(x::ForwardDiff.DiffResults.DiffResult,
::Type{Val{counter}} = Val{0}) where {counter}
Any
Expand Down
12 changes: 12 additions & 0 deletions test/forwarddiff_dual_detection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,15 @@ ode = ODEProblem(f, [0.0, 0.0], (0, 1))
@inferred DiffEqBase.anyeltypedual(ode)
ode = NonlinearProblem(f, [0.0, 0.0], (0, 1))
@inferred DiffEqBase.anyeltypedual(ode)

# Issue https://github.com/SciML/DiffEqBase.jl/issues/1021
f(u, p, t) = 1.01 * u
struct Foo{T}
sol::T
end
u0 = 1 / 2
tspan = (0.0, 1.0)
prob = ODEProblem{false}(f, u0, tspan)
foo = SciMLBase.build_solution(
prob, DiffEqBase.InternalEuler.FwdEulerAlg(), [u0, u0], [0.0, 1.0])
DiffEqBase.anyeltypedual((; x = foo))

0 comments on commit cdbe856

Please sign in to comment.