Skip to content
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
2 changes: 1 addition & 1 deletion src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ for f in (:(Base.:^), :(NaNMath.pow))
begin
v = value(x)
expv = ($f)(v, y)
if y == zero(y)
if y == zero(y) || iszero(partials(x))
new_partials = zero(partials(x))
else
new_partials = partials(x) * y * ($f)(v, y - 1)
Expand Down
6 changes: 6 additions & 0 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using DiffRules
import Calculus

struct TestTag end
struct OuterTestTag end

samerng() = MersenneTwister(1)

Expand All @@ -26,6 +27,8 @@ dual_isapprox(a::Dual{T,T1,T2}, b::Dual{T3,T4,T5}) where {T,T1,T2,T3,T4,T5} = er

ForwardDiff.:≺(::Type{TestTag()}, ::Int) = true
ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
ForwardDiff.:≺(::Type{TestTag}, ::Type{OuterTestTag}) = true
ForwardDiff.:≺(::Type{OuterTestTag}, ::Type{TestTag}) = false

for N in (0,3), M in (0,4), V in (Int, Float32)
println(" ...testing Dual{TestTag(),$V,$N} and Dual{TestTag(),Dual{TestTag(),$V,$M},$N}")
Expand Down Expand Up @@ -553,6 +556,9 @@ end
@test pow(x3, 2) === x3^2 === x3 * x3
@test pow(x2, 1) === x2^1 === x2
@test pow(x1, 0) === x1^0 === Dual{:t1}(1.0, 0.0)
y = Dual{typeof(TestTag())}(1.0, 0.0, 1.0);
x = Dual{typeof(OuterTestTag())}(0*y, 0*y);
@test iszero(ForwardDiff.partials(ForwardDiff.partials(x^y)[1]))
end

@testset "Type min/max" begin
Expand Down