Skip to content

Commit db39e48

Browse files
committed
handle NoTangent in copyto!
1 parent fd1c3a6 commit db39e48

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/rulesets/Base/array.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,14 @@ _instantiate_zeros(ẋs::AbstractArray{<:AbstractArray}, xs) = ẋs
8686
#####
8787

8888
function frule((_, ẏ, ẋ), ::typeof(copyto!), y::AbstractArray, x)
89-
return copyto!(y, x), copyto!(ẏ, ẋ)
89+
ifisa AbstractZero
90+
# it's allowed to have an imutable zero tangent for ẏ as long as ẋ is zero
91+
# TODO should this be handled here or in the AD?
92+
@assert iszero(ẋ)
93+
else
94+
copyto!(ẏ, ẋ)
95+
end
96+
return copyto!(y, x), ẏ
9097
end
9198

9299
function frule((_, ẏ, _, ẋ), ::typeof(copyto!), y::AbstractArray, i::Integer, x, js::Integer...)

0 commit comments

Comments
 (0)