@@ -100,7 +100,7 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
100
100
@test ProjectTo (Bool[]) isa ProjectTo{NoTangent}
101
101
end
102
102
103
- @testset " Base: zero-arrays & Ref " begin
103
+ @testset " Base: zero-arrays" begin
104
104
pzed = ProjectTo (fill (1.0 ))
105
105
@test pzed (fill (3.14 )) == fill (3.14 ) # easy
106
106
@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))
110
110
@test_throws DimensionMismatch ProjectTo ([1 ])(3.14 + im) # other array projectors don't accept numbers
111
111
@test_throws DimensionMismatch ProjectTo (hcat ([1 , 2 ]))(3.14 )
112
112
@test pzed isa ProjectTo{AbstractArray}
113
+ end
113
114
115
+ @testset " Base: Ref" begin
114
116
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 }
118
120
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
120
122
121
123
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}
123
125
@test_throws DimensionMismatch prefvec (Ref {Any} (1 : 5 ))
124
126
end
125
127
@@ -305,6 +307,19 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
305
307
@test unthunk (pth) === 6.0 + 0.0im
306
308
end
307
309
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
+
308
323
@testset " display" begin
309
324
@test repr (ProjectTo (1.1 )) == " ProjectTo{Float64}()"
310
325
@test occursin (" ProjectTo{AbstractArray}(element" , repr (ProjectTo ([1 , 2 , 3 ])))
0 commit comments