Skip to content

Commit 25ebf77

Browse files
Reduce potential for nontermination in Derivative
1 parent 0097578 commit 25ebf77

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

src/differentials.jl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Differential(x) = Differential(x,1)
77
Base.show(io::IO, D::Differential) = print(io,"($(D.x),$(D.order))")
88
Base.convert(::Type{Expr}, D::Differential) = D
99

10-
function Derivative end
1110
(D::Differential)(x::Operation) = Operation(D, Expression[x])
1211
function (D::Differential)(x::Variable)
1312
D.x === x && return Constant(1)
@@ -34,11 +33,7 @@ end
3433
expand_derivatives(x) = x
3534

3635
# Don't specialize on the function here
37-
function Derivative(O::Operation,idx)
38-
# This calls the Derivative dispatch from the user or pre-defined code
39-
Derivative(O.op, O.args, Val(idx))
40-
end
41-
Derivative(op, args, idx) = Derivative(op, (args...,), idx)
36+
Derivative(O::Operation, idx) = Derivative(O.op, (O.args...,), Val(idx))
4237

4338
# Pre-defined derivatives
4439
import DiffRules, SpecialFunctions, NaNMath

test/derivatives.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ dcsch = D(csch(t))
1717
dsinsin = D(sin(sin(t)))
1818
@test expand_derivatives(dsinsin) == cos(sin(t))*cos(t)
1919
# Binary
20-
dpow1 = Derivative(^,[x, y],Val(1))
21-
dpow2 = Derivative(^,[x, y],Val(2))
20+
dpow1 = Derivative(^, (x, y), Val(1))
21+
dpow2 = Derivative(^, (x, y), Val(2))
2222
@test dpow1 == y*x^(y-1)
2323
@test dpow2 == x^y*log(x)
2424

0 commit comments

Comments
 (0)