@@ -11,6 +11,9 @@ Base.real(x::Dual) = x
11
11
Base. float (x:: Dual ) = Dual (float (x. value), float (x. partial))
12
12
Base. zero (x:: Dual ) = Dual (zero (x. value), zero (x. partial))
13
13
14
+ # Trivial struct
15
+ struct NoSuperType end
16
+
14
17
@testset " projection" begin
15
18
16
19
# ####
@@ -24,7 +27,6 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
24
27
@test ProjectTo (2.0 + 3.0im )(1 + 1im ) === 1.0 + 1.0im
25
28
@test ProjectTo (2.0 )(1 + 1im ) === 1.0
26
29
27
-
28
30
# storage
29
31
@test ProjectTo (1 )(pi ) === pi
30
32
@test ProjectTo (1 + im)(pi ) === ComplexF64 (pi )
@@ -94,9 +96,10 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
94
96
@test y1[1 ] == [1 2 ]
95
97
@test ! (y1 isa Adjoint) && ! (y1[1 ] isa Adjoint)
96
98
97
- # arrays of unknown things
98
- @test_throws MethodError ProjectTo ([:x , :y ])
99
- @test_throws MethodError ProjectTo (Any[:x , :y ])
99
+ # arrays of other things
100
+ @test ProjectTo ([:x , :y ]) isa ProjectTo{NoTangent}
101
+ @test ProjectTo (Any[' x' , " y" ]) isa ProjectTo{NoTangent}
102
+ @test ProjectTo ([(1 ,2 ), (3 ,4 ), (5 ,6 )]) isa ProjectTo{AbstractArray}
100
103
101
104
@test ProjectTo (Any[1 , 2 ])(1 : 2 ) == [1.0 , 2.0 ] # projects each number.
102
105
@test Tuple (ProjectTo (Any[1 , 2 + 3im ])(1 : 2 )) === (1.0 , 2.0 + 0.0im )
@@ -140,6 +143,12 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
140
143
@test ProjectTo (Ref ([false ]' )) isa ProjectTo{NoTangent}
141
144
end
142
145
146
+ @testset " Base: non-diff" begin
147
+ @test ProjectTo (:a )(1 ) == NoTangent ()
148
+ @test ProjectTo (' b' )(2 ) == NoTangent ()
149
+ @test ProjectTo (" cde" )(345 ) == NoTangent ()
150
+ end
151
+
143
152
# ####
144
153
# #### `LinearAlgebra`
145
154
# ####
@@ -301,6 +310,10 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
301
310
# #### `ChainRulesCore`
302
311
# ####
303
312
313
+ @testset " pass-through" begin
314
+ @test ProjectTo (NoSuperType ()) === identity
315
+ end
316
+
304
317
@testset " AbstractZero" begin
305
318
pz = ProjectTo (ZeroTangent ())
306
319
pz (0 ) == NoTangent ()
0 commit comments