Skip to content

Commit 7b255be

Browse files
Handle dual detection on SciMLFunctions
1 parent 74d34fb commit 7b255be

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/forwarddiff.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ const FORWARDDIFF_AUTODETECTION_FAILURE_MESSAGE = """
155155
end
156156
```
157157
158+
To opt a type out of the dual checking, define an overload
159+
that returns Any. For example:
160+
161+
```julia
162+
function DiffEqBase.anyeltypedual(::YourType, ::Type{Val{counter}}) where {counter}
163+
Any
164+
end
165+
```
166+
158167
If you have defined this on a common type which should
159168
be more generally supported, please open a pull request
160169
adding this dispatch. If you need help defining this dispatch,
@@ -338,6 +347,8 @@ function anyeltypedual(x::NamedTuple, ::Type{Val{counter}} = Val{0}) where {coun
338347
anyeltypedual(values(x))
339348
end
340349

350+
DiffEqBase.anyeltypedual(f::SciMLBase.AbstractSciMLFunction, ::Type{Val{counter}}) where {counter} = Any
351+
341352
@inline promote_u0(::Nothing, p, t0) = nothing
342353

343354
@inline function promote_u0(u0, p, t0)

test/forwarddiff_dual_detection.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,4 @@ prob = ODEProblem{false}(f, u0, tspan)
347347
foo = SciMLBase.build_solution(
348348
prob, DiffEqBase.InternalEuler.FwdEulerAlg(), [u0, u0], [0.0, 1.0])
349349
DiffEqBase.anyeltypedual((; x = foo))
350+
DiffEqBase.anyeltypedual((; x = foo, y = prob.f))

0 commit comments

Comments
 (0)