Skip to content

Commit 49bc8ac

Browse files
committed
project ZeroTangent to natural tangent for some number types
1 parent fbb4936 commit 49bc8ac

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/projection.jl

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ end
191191
# understands, including a mix of Zeros & reals. Other cases, we just let through:
192192
(project::ProjectTo{<:Number})(dx::Tangent{<:Complex}) = project(Complex(dx.re, dx.im))
193193
(::ProjectTo{<:Number})(dx::Tangent{<:Number}) = dx
194+
(::ProjectTo{T})(::ZeroTangent) where T <: Real = zero(T)
194195

195196
# Arrays
196197
# If we don't have a more specialized `ProjectTo` rule, we just assume that there is

test/projection.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ struct NoSuperType end
3737
@test ProjectTo(1.0)(2) === 2.0
3838

3939
# Tangents
40-
ProjectTo(1.0f0 + 2im)(Tangent{ComplexF64}(; re=1, im=NoTangent())) ===
41-
1.0f0 + 0.0f0im
42-
43-
@test 1.0 === ProjectTo(1.0)(Tangent{ComplexF64}(; re=1, im=NoTangent()))
40+
complex_tangent = Tangent{ComplexF64}(; re=1, im=NoTangent())
41+
@test ProjectTo(1.0f0 + 2im)(complex_tangent) === 1.0f0 + 0.0f0im
42+
@test ProjectTo(1.0)(complex_tangent) === 1.0
43+
@test ProjectTo(1.0)(ZeroTangent()) === 0.0
4444
end
4545

4646
@testset "Dual" begin # some weird Real subtype that we should basically leave alone

0 commit comments

Comments
 (0)