Skip to content

Commit 9918900

Browse files
committed
Fix ADing Tangent constructor
1 parent 730ea67 commit 9918900

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/extra_rules.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,12 @@ end
291291
# https://github.com/JuliaDiff/ChainRulesCore.jl/issues/607
292292
Base.:(==)(x::Number, ::ZeroTangent) = iszero(x)
293293
Base.:(==)(::ZeroTangent, x::Number) = iszero(x)
294-
Base.hash(x::ZeroTangent, h::UInt64) = hash(0, h)
294+
Base.hash(x::ZeroTangent, h::UInt64) = hash(0, h)
295+
296+
# should this be in ChainRules/ChainRulesCore?
297+
# Avoid making nested backings, a Tangent is already a valid Tangent for a Tangent,
298+
# or a valid second order Tangent for the primal
299+
function frule((_, ẋ), T::Type{<:Tangent}, x)
300+
::Tangent
301+
return T(x), ẋ
302+
end

0 commit comments

Comments
 (0)