Skip to content

Conversation

@devmotion
Copy link
Member

The PR fixes the following error on the master branch:

julia> using ForwardDiff

julia> ForwardDiff.derivative(x -> sum(1 .+ x .* (0:0.1:1)), 1)
ERROR: MethodError: ForwardDiff.Dual{ForwardDiff.Tag{var"#3#4", Int64}, Float64, 1}(::Base.TwicePrecision{ForwardDiff.Dual{ForwardDiff.Tag{var"#3#4", Int64}, Float64, 1}}) is ambiguous.

Candidates:
  ForwardDiff.Dual{T, V, N}(x) where {T, V, N}
    @ ForwardDiff ~/.julia/packages/ForwardDiff/L9SLV/src/dual.jl:77
  (::Type{T})(x::Base.TwicePrecision) where T<:Number
    @ Base twiceprecision.jl:265

Possible fix, define
  ForwardDiff.Dual{T, V, N}(::Base.TwicePrecision) where {N, V, T}

Stacktrace:
 [1] broadcasted(::Base.Broadcast.DefaultArrayStyle{…}, ::typeof(+), x::Int64, r::StepRangeLen{…})
   @ Base.Broadcast ./broadcast.jl:1120
 [2] broadcasted
   @ ./broadcast.jl:1326 [inlined]
 [3] (::var"#3#4")(x::ForwardDiff.Dual{ForwardDiff.Tag{var"#3#4", Int64}, Int64, 1})
   @ Main ./REPL[4]:1
 [4] derivative(f::var"#3#4", x::Int64)
   @ ForwardDiff ~/.julia/packages/ForwardDiff/L9SLV/src/derivative.jl:14
 [5] top-level scope
   @ REPL[4]:1
Some type information was truncated. Use `show(err)` to see complete types.

@devmotion devmotion merged commit 826d919 into master Oct 30, 2024
3 of 4 checks passed
@devmotion devmotion deleted the dw/method_ambiguity branch October 30, 2024 09:32
devmotion added a commit that referenced this pull request Nov 1, 2024
* Fix method ambiguity for `Base.TwicePrecision`

* Mark tests as not broken
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants