- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 120
 
Closed
Labels
Description
The function anyeltypedual fails on empty Pairs objects (and on objects containing empty Pairs objects). If my understanding is correct, it should return Any instead.
My current stopgap solution is to add the following methods to forwarddiff.jl (I have to add them to the package to make them work with objects containing empty Pairs, I guess because of the @generated functions and world age problems).
anyeltypedual(::@Kwargs{}, ::Type{Val{counter}} = Val{0}) where {counter} = Any
anyeltypedual(::Type{@Kwargs{}}, ::Type{Val{counter}} = Val{0}) where {counter} = AnyHere is a MWE (using DiffEqBase v6.154.0). Using objects containing empty Pairs instead, one eventually gets the same errors.
julia> using DiffEqBase
julia> DiffEqBase.anyeltypedual(pairs((;)))
ERROR: MethodError: anyeltypedual(::Type{Union{}}, ::Type{Val{1}}) is ambiguous.
Candidates:
  anyeltypedual(x::Type{T}, ::Type{Val{counter}}) where {T<:ForwardDiff.AbstractConfig, counter}
    @ DiffEqBase ~/.julia/packages/DiffEqBase/sCsah/src/forwarddiff.jl:188
  anyeltypedual(::Type{<:SciMLBase.AbstractTimeseriesSolution{T, N}}, ::Type{Val{counter}}) where {T, N, counter}
    @ DiffEqBase ~/.julia/packages/DiffEqBase/sCsah/src/forwarddiff.jl:194
  anyeltypedual(::Type{T}, ::Type{Val{counter}}) where {T<:ForwardDiff.Dual, counter}
    @ DiffEqBase ~/.julia/packages/DiffEqBase/sCsah/src/forwarddiff.jl:235
  anyeltypedual(::Type{T}, ::Type{Val{counter}}) where {T<:(Tuple{Vararg{T, N}} where {N, T}), counter}
    @ DiffEqBase ~/.julia/packages/DiffEqBase/sCsah/src/forwarddiff.jl:254
  anyeltypedual(::Type{T}, ::Type{Val{counter}}) where {T<:Union{Set, AbstractArray}, counter}
    @ DiffEqBase ~/.julia/packages/DiffEqBase/sCsah/src/forwarddiff.jl:239
  anyeltypedual(x::Type{T}, ::Type{Val{counter}}) where {T<:DiffResults.DiffResult, counter}
    @ DiffEqBase ~/.julia/packages/DiffEqBase/sCsah/src/forwarddiff.jl:203
Possible fix, define
  anyeltypedual(::Type{Union{}}, ::Type{Val{counter}}) where counter
Stacktrace:
  [1] (::DiffEqBase.var"#80#81"{Int64})(x::Type)
    @ DiffEqBase ~/.julia/packages/DiffEqBase/sCsah/src/forwarddiff.jl:102
  [2] (::Base.MappingRF{DiffEqBase.var"#80#81"{Int64}, Base.BottomRF{typeof(DiffEqBase.promote_dual)}})(acc::Type, x::Type)
    @ Base ./reduce.jl:100
  [3] _foldl_impl(op::Base.MappingRF{DiffEqBase.var"#80#81"{…}, Base.BottomRF{…}}, init::Type, itr::Core.SimpleVector)
    @ Base ./reduce.jl:62
  [4] foldl_impl
    @ ./reduce.jl:48 [inlined]
  [5] mapfoldl_impl
    @ ./reduce.jl:44 [inlined]
  [6] mapfoldl
    @ ./reduce.jl:175 [inlined]
  [7] mapreduce
    @ ./reduce.jl:307 [inlined]
  [8] diffeqmapreduce(f::DiffEqBase.var"#80#81"{Int64}, op::typeof(DiffEqBase.promote_dual), x::Core.SimpleVector)
    @ DiffEqBase ~/.julia/packages/DiffEqBase/sCsah/src/forwarddiff.jl:55
  [9] #s86#79
    @ ~/.julia/packages/DiffEqBase/sCsah/src/forwarddiff.jl:102 [inlined]
 [10] var"#s86#79"(counter::Any, ::Any, x::Any, ::Any)
    @ DiffEqBase ./none:0
 [11] (::Core.GeneratedFunctionStub)(::UInt64, ::LineNumberNode, ::Any, ::Vararg{Any})
    @ Core ./boot.jl:602
 [12] anyeltypedual(x::@Kwargs{})
    @ DiffEqBase ~/.julia/packages/DiffEqBase/sCsah/src/forwarddiff.jl:95
 [13] top-level scope
    @ REPL[3]:1
Some type information was truncated. Use `show(err)` to see complete types.