Symbolics.jl
Symbolics.jl copied to clipboard
Type ambiguity in isequal(Num, ForwardDiff.Dual)
I want to fix https://github.com/SciML/ModelingToolkit.jl/issues/2997, and this seems to be the root cause:
using Symbolics, ForwardDiff, Test
@variables x
xfunc(xval) = isequal(x, xval) ? xval : xval
@test ForwardDiff.derivative(xfunc, 0.0) == 1.0
Error During Test at REPL[5]:1
Test threw exception
Expression: ForwardDiff.derivative(xfunc, 0.0) == 1.0
MethodError: isequal(::Num, ::ForwardDiff.Dual{ForwardDiff.Tag{typeof(xfunc), Float64}, Float64, 1}) is ambiguous.
Candidates:
isequal(a::Num, b::Number)
@ Symbolics C:\Users\herma\.julia\dev\Symbolics\src\num.jl:132
isequal(x::Real, y::ForwardDiff.Dual{Ty}) where Ty
@ ForwardDiff C:\Users\herma\.julia\packages\ForwardDiff\PcZ48\src\dual.jl:145
Possible fix, define
isequal(::Num, ::ForwardDiff.Dual{Ty}) where Ty
Stacktrace:
[1] xfunc(xval::ForwardDiff.Dual{ForwardDiff.Tag{typeof(xfunc), Float64}, Float64, 1})
@ Main .\REPL[4]:1
[2] derivative(f::typeof(xfunc), x::Float64)
@ ForwardDiff C:\Users\herma\.julia\packages\ForwardDiff\PcZ48\src\derivative.jl:14
[3] macro expansion
@ C:\Users\herma\.julia\juliaup\julia-1.10.4+0.x64.w64.mingw32\share\julia\stdlib\v1.10\Test\src\Test.jl:669 [inlined]
[4] top-level scope
@ REPL[5]:1
ERROR: There was an error during testing
Possible fix, define isequal(::Num, ::ForwardDiff.Dual{Ty}) where Ty
from the error message could be an option.
Yep, thanks! I am preparing a PR now.
This was fixed by https://github.com/JuliaSymbolics/Symbolics.jl/pull/1247.