Skip to content

Commit

Permalink
Merge pull request #923 from SciML/returns_forwarddif
Browse files Browse the repository at this point in the history
Specialize forwarddiff dual detection for Returns
  • Loading branch information
ChrisRackauckas authored Sep 12, 2023
2 parents 7f15b4e + 1c099a6 commit 3bf4879
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/forwarddiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ anyeltypedual(x::Union{ForwardDiff.AbstractConfig, Module}, counter = 0) = Any
anyeltypedual(x::Type{T}, counter = 0) where {T <: ForwardDiff.AbstractConfig} = Any
anyeltypedual(x::SciMLBase.RecipesBase.AbstractPlot, counter = 0) = Any

if VERSION >= v"1.7"
anyeltypedual(x::Returns, counter = 0) = anyeltypedual(x.value, counter)
end

if isdefined(PreallocationTools, :FixedSizeDiffCache)
anyeltypedual(x::PreallocationTools.FixedSizeDiffCache, counter = 0) = Any
end
Expand Down
6 changes: 1 addition & 5 deletions test/forwarddiff_dual_detection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ p_possibilities17 = [
(Mod, ForwardDiff.Dual(2.0)), (() -> 2.0, ForwardDiff.Dual(2.0)),
(Base.pointer([2.0]), ForwardDiff.Dual(2.0)),
]
VERSION >= v"1.7" && VERSION < v"1.9" &&
push!(p_possibilities17, Returns((a = 2, b = 1.3, c = ForwardDiff.Dual(2.0f0))))
VERSION >= v"1.7" && push!(p_possibilities17, Returns((a = 2, b = 1.3, c = ForwardDiff.Dual(2.0f0))))

for p in p_possibilities17
@show p
Expand Down Expand Up @@ -128,9 +127,6 @@ p_possibilities_uninferrred = [
(; x = Vector{Float64}(undef, 2), y = [[MyStruct3(ForwardDiff.Dual(2.0))]]),
(; x = Matrix{Any}(undef, 2, 2), y = [[MyStruct3(ForwardDiff.Dual(2.0))]]),
]
VERSION >= v"1.9" &&
push!(p_possibilities_uninferrred,
Returns((a = 2, b = 1.3, c = ForwardDiff.Dual(2.0f0))))

for p in p_possibilities_uninferrred
@show p
Expand Down

0 comments on commit 3bf4879

Please sign in to comment.