JuliaDiff / JuliaDiff/ForwardDiff.jl
Using ArbFloat fails at subtraction / addition of Dual and ArbFloat
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 1k
- Forks
- 160
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I cannot use jacobian with ArbFloat type. The following code runs when T = Float64
using ArbFloats
using ForwardDiff
T = Float64 # ArbFloat
M = 3
F = [T(0.0) for i in 1:M]
x0 = [T(-1.0) for i in 1:M]
function f!(F,x)
for i in eachindex(F)
F[i] = x[i] - T(1.0)
end
end
ForwardDiff.jacobian(f!,F,x0)
but fails when I set T = ArbFloat with the following error:
ERROR: LoadError: MethodError: +(::ForwardDiff.Dual{ForwardDiff.Tag{#f!,ArbFloats.ArbFloat{116}},ArbFloats.ArbFloat{116},3}, ::ArbFloats.ArbFloat{116}) is ambiguous. Candidates:
+(x::ForwardDiff.Dual{Tx,V,N} where N where V<:Real, y::AbstractFloat) where Tx in ForwardDiff at /home/gluon/.julia/v0.6/ForwardDiff/src/dual.jl:103
+(x::ForwardDiff.Dual{Tx,V,N} where N where V<:Real, y::Real) where Tx in ForwardDiff at /home/gluon/.julia/v0.6/ForwardDiff/src/dual.jl:103
+(x::R, y::T) where {T<:ArbFloats.ArbFloat, R<:Real} in ArbFloats at /home/gluon/.julia/v0.6/ArbFloats/src/math/arith.jl:60
Possible fix, define
+(::ForwardDiff.Dual{Tx,V,N} where N where V<:Real, ::T<:ArbFloats.ArbFloat)
Stacktrace:
[1] (::Atom.##110#114{String,String})() at /home/gluon/.julia/v0.6/Atom/src/eval.jl:104
[2] withpath(::Atom.##110#114{String,String}, ::String) at /home/gluon/.julia/v0.6/CodeTools/src/utils.jl:30
[3] withpath(::Function, ::String) at /home/gluon/.julia/v0.6/Atom/src/eval.jl:38
[4] didWriteToREPL(::Atom.##109#113{String,String}) at /home/gluon/.julia/v0.6/Atom/src/repl.jl:129
[5] hideprompt(::Atom.##109#113{String,String}) at /home/gluon/.julia/v0.6/Atom/src/repl.jl:65
[6] macro expansion at /home/gluon/.julia/v0.6/Atom/src/eval.jl:99 [inlined]
[7] (::Atom.##108#112{Dict{String,Any}})() at ./task.jl:80
while loading /media/DATA/PhD/code/sandbox/sandbox.jl, in expression starting on line 57
This is just a test code which I produced to show the error, the actual code is different but leads to same kind of errors. Can someone say me what is going on here and how to fix this? Thanks.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the reproducer with T = ArbFloat and inspect the conflicting methods in ForwardDiff/src/dual.jl and ArbFloats/src/math/arith.jl. Trace the subtraction or addition dispatch involved in ForwardDiff.jacobian, then verify that the example completes without an ambiguous-method error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100