Skip to content

Commit 91de6d4

Browse files
committed
also fix a method ambiguity
1 parent f3fd24f commit 91de6d4

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/projection.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ ProjectTo(::Any) # just to attach docstring
124124
# Zero
125125
ProjectTo(::AbstractZero) = ProjectTo{NoTangent}() # Any x::Zero in forward pass makes this one projector,
126126
(::ProjectTo{NoTangent})(dx) = NoTangent() # but this is the projection only for nonzero gradients,
127-
(::ProjectTo{NoTangent})(::NoTangent) = NoTangent() # and this one solves an ambiguity.
127+
(::ProjectTo{NoTangent})(dx::AbstractZero) = dx # and this one solves an ambiguity.
128128

129129
# Also, any explicit construction with fields, where all fields project to zero, itself
130130
# projects to zero. This simplifies projectors for wrapper types like Diagonal([true, false]).

test/projection.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,12 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
299299
@testset "AbstractZero" begin
300300
pz = ProjectTo(ZeroTangent())
301301
pz(0) == NoTangent()
302-
@test_broken pz(ZeroTangent()) === ZeroTangent() # not sure how NB this is to preserve
302+
@test pz(ZeroTangent()) === ZeroTangent() # not sure how NB this is to preserve
303303
@test pz(NoTangent()) === NoTangent()
304304

305305
pb = ProjectTo(true) # Bool is categorical
306306
@test pb(2) === NoTangent()
307+
@test pb(ZeroTangent()) isa AbstractZero # was a method ambiguity!
307308

308309
# all projectors preserve Zero, and specific type, via one fallback method:
309310
@test ProjectTo(pi)(ZeroTangent()) === ZeroTangent()

0 commit comments

Comments
 (0)