@@ -100,7 +100,7 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
100100 @test ProjectTo (Bool[]) isa ProjectTo{NoTangent}
101101 end
102102
103- @testset " Base: zero-arrays & Ref " begin
103+ @testset " Base: zero-arrays" begin
104104 pzed = ProjectTo (fill (1.0 ))
105105 @test pzed (fill (3.14 )) == fill (3.14 ) # easy
106106 @test pzed (fill (3 )) == fill (3.0 ) # broadcast type change must not produce number
@@ -110,16 +110,18 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
110110 @test_throws DimensionMismatch ProjectTo ([1 ])(3.14 + im) # other array projectors don't accept numbers
111111 @test_throws DimensionMismatch ProjectTo (hcat ([1 , 2 ]))(3.14 )
112112 @test pzed isa ProjectTo{AbstractArray}
113+ end
113114
115+ @testset " Base: Ref" begin
114116 pref = ProjectTo (Ref (2.0 ))
115- @test pref (Ref (3 + im))[] === 3.0
116- @test pref (4 )[] === 4.0 # also re-wraps scalars
117- @test pref (Ref {Any} (5.0 )) isa Base. RefValue{Float64 }
117+ @test pref (Ref (3 + im)). x === 3.0
118+ @test pref (4 ). x === 4.0 # also re-wraps scalars
119+ @test pref (Ref {Any} (5.0 )) isa Tangent{ <: Base.RefValue }
118120 pref2 = ProjectTo (Ref {Any} (6 + 7im ))
119- @test pref2 (Ref (8 ))[] === 8.0 + 0.0im
121+ @test pref2 (Ref (8 )). x === 8.0 + 0.0im
120122
121123 prefvec = ProjectTo (Ref ([1 , 2 , 3 + 4im ])) # recurses into contents
122- @test prefvec (Ref (1 : 3 )) isa Base . RefValue{ Vector{ComplexF64} }
124+ @test prefvec (Ref (1 : 3 )). x isa Vector{ComplexF64}
123125 @test_throws DimensionMismatch prefvec (Ref {Any} (1 : 5 ))
124126 end
125127
@@ -305,6 +307,19 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
305307 @test unthunk (pth) === 6.0 + 0.0im
306308 end
307309
310+ @testset " Tangent" begin
311+ x = 1 : 3.0
312+ dx = Tangent {typeof(x)} (; step= 0.1 , ref= NoTangent ());
313+ @test ProjectTo (x)(dx) isa Tangent
314+ @test ProjectTo (x)(dx). step === 0.1
315+ @test ProjectTo (x)(dx). offset isa AbstractZero
316+
317+ pref = ProjectTo (Ref (2.0 ))
318+ dy = Tangent {typeof(Ref(2.0))} (x = 3 + 4im )
319+ @test pref (dy) isa Tangent{<: Base.RefValue }
320+ @test pref (dy). x === 3.0
321+ end
322+
308323 @testset " display" begin
309324 @test repr (ProjectTo (1.1 )) == " ProjectTo{Float64}()"
310325 @test occursin (" ProjectTo{AbstractArray}(element" , repr (ProjectTo ([1 , 2 , 3 ])))
0 commit comments