Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve isequal(Num, ForwardDiff.Dual) ambiguity #1247

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading