Skip to content

Commit b01bc64

Browse files
committed
avoid method redefinition
1 parent 1abd172 commit b01bc64

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/differentials.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,11 @@ for (modu, fun, arity) ∈ DiffRules.diffrules()
188188
else
189189
DiffRules.diffrule(modu, fun, ntuple(k->:(args[$k]), arity)...)[i]
190190
end
191-
@eval derivative(::typeof($modu.$fun), args::NTuple{$arity,Any}, ::Val{$i}) = $expr
191+
@eval derivative(::typeof($modu.$fun), args::NTuple{$arity,Any}, ::Val{$i}) = (x = $expr; !(x isa Expression || x isa Constant) ? Constant(x) : x)
192192
end
193193
end
194194

195195
derivative(::typeof(+), args::NTuple{N,Any}, ::Val) where {N} = Constant(1)
196-
derivative(::typeof(-), args::NTuple{2,Any}, ::Val{1}) = Constant(1)
197-
derivative(::typeof(-), args::NTuple{2,Any}, ::Val{2}) = Constant(-1)
198196
derivative(::typeof(*), args::NTuple{N,Any}, ::Val{i}) where {N,i} = make_operation(*, deleteat!(collect(args), i))
199197
derivative(::typeof(one), args::Tuple{<:Any}, ::Val) = Constant(0)
200198

0 commit comments

Comments
 (0)