Skip to content

Commit 47c4009

Browse files
committed
Implement zero for NotImplemented
1 parent 721877f commit 47c4009

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/tangent_types/notimplemented.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,8 @@ Base.:/(x::AbstractZero, ::NotImplemented) = x
4848
Base.:/(x::NotImplemented, ::AbstractThunk) = throw(NotImplementedException(x))
4949
Base.:/(::AbstractThunk, x::NotImplemented) = throw(NotImplementedException(x))
5050

51-
Base.zero(x::NotImplemented) = throw(NotImplementedException(x))
52-
function Base.zero(::Type{<:NotImplemented})
53-
return throw(
54-
NotImplementedException(
55-
@not_implemented(
56-
"`zero` is not defined for missing tangents of type `NotImplemented`"
57-
)
58-
),
59-
)
60-
end
51+
Base.zero(::NotImplemented) = ZeroTangent()
52+
Base.zero(::Type{<:NotImplemented}) = ZeroTangent()
6153

6254
Base.iterate(x::NotImplemented) = throw(NotImplementedException(x))
6355
Base.iterate(x::NotImplemented, ::Any) = throw(NotImplementedException(x))

test/tangent_types/notimplemented.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
x = rand()
1010
thunk = @thunk(x^2)
1111

12+
# zero
13+
@test @inferred(zero(ni)) === ZeroTangent()
14+
@test @inferred(zero(typeof(ni2))) === ZeroTangent()
15+
@test !iszero(ni)
16+
1217
# conjugate
1318
@test conj(ni) === ni
1419

@@ -58,8 +63,6 @@
5863
@test_throws E a / ni
5964
end
6065
@test_throws E ni / ni2
61-
@test_throws E zero(ni)
62-
@test_throws E zero(typeof(ni))
6366
@test_throws E iterate(ni)
6467
@test_throws E iterate(ni, nothing)
6568
@test_throws E adjoint(ni)

0 commit comments

Comments
 (0)