Skip to content

Commit 3c756ec

Browse files
author
Miha Zgubic
committed
add notimplemented
1 parent 153ac1a commit 3c756ec

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/tangent_arithmetic.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ for T in (:AbstractThunk, :Tangent, :Any)
3939
@eval LinearAlgebra.dot(x::NotImplemented, ::$T) = x
4040
@eval LinearAlgebra.dot(::$T, x::NotImplemented) = x
4141
end
42+
# unary :- is the same as multiplication by -1
43+
Base.:-(x::NotImplemented) = x
4244

4345
# subtraction throws an exception: in AD we add tangents but do not subtract them
4446
# subtraction happens eg. in gradient descent which can't be performed with `NotImplemented`
45-
Base.:-(x::NotImplemented) = throw(NotImplementedException(x))
4647
Base.:-(x::NotImplemented, ::NotImplemented) = throw(NotImplementedException(x))
4748
for T in (:ZeroTangent, :NoTangent, :AbstractThunk, :Tangent, :Any)
4849
@eval Base.:-(x::NotImplemented, ::$T) = throw(NotImplementedException(x))

test/tangent_types/notimplemented.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@test ni2 + ni === ni2
2323

2424
# multiplication and dot product
25+
@test -ni == ni
2526
for a in (true, x, thunk)
2627
@test ni * a === ni
2728
@test a * ni === ni

0 commit comments

Comments
 (0)