Skip to content

Commit

Permalink
Merge pull request #1247 from hersle/dual_num_isequal
Browse files Browse the repository at this point in the history
 Resolve isequal(Num, ForwardDiff.Dual) ambiguity
  • Loading branch information
ChrisRackauckas authored Aug 29, 2024
2 parents c91be2e + f0bcc47 commit db877fb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ext/SymbolicsForwardDiffExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@ function binary_dual_definition(M, f, Ts)
return expr
end

#####################
# Generic Functions #
#####################

# Predicates #
#------------#

for pred in [:isequal, :(==)]
@eval begin
@define_binary_dual_op(
Base.$(pred),
$(pred)(value(x), value(y)) && $(pred)(partials(x), partials(y)),
$(pred)(value(x), y) && iszero(partials(x)),
$(pred)(x, value(y)) && iszero(partials(y)),
$AMBIGUOUS_TYPES
)
end
end

###################################
# General Mathematical Operations #
###################################
Expand Down
7 changes: 7 additions & 0 deletions test/forwarddiff_symbolic_dual_ops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,10 @@ for f ∈ (hypot, muladd)
end

# fma is not defined for Symbolics.Num

# https://github.com/JuliaSymbolics/Symbolics.jl/issues/1246
@testset "isequal type ambiguity" begin
@variables z
y(x) = isequal(z, x) ? 0 : x
@test ForwardDiff.derivative(y, 0) == 1 # expect ∂(x)/∂x
end

0 comments on commit db877fb

Please sign in to comment.