@@ -11,6 +11,9 @@ Base.real(x::Dual) = x
1111Base. float (x:: Dual ) = Dual (float (x. value), float (x. partial))
1212Base. zero (x:: Dual ) = Dual (zero (x. value), zero (x. partial))
1313
14+ # Trivial struct
15+ struct NoSuperType end
16+
1417@testset " projection" begin
1518
1619 # ####
@@ -24,7 +27,6 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
2427 @test ProjectTo (2.0 + 3.0im )(1 + 1im ) === 1.0 + 1.0im
2528 @test ProjectTo (2.0 )(1 + 1im ) === 1.0
2629
27-
2830 # storage
2931 @test ProjectTo (1 )(pi ) === pi
3032 @test ProjectTo (1 + im)(pi ) === ComplexF64 (pi )
@@ -94,9 +96,10 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
9496 @test y1[1 ] == [1 2 ]
9597 @test ! (y1 isa Adjoint) && ! (y1[1 ] isa Adjoint)
9698
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}
100103
101104 @test ProjectTo (Any[1 , 2 ])(1 : 2 ) == [1.0 , 2.0 ] # projects each number.
102105 @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))
140143 @test ProjectTo (Ref ([false ]' )) isa ProjectTo{NoTangent}
141144 end
142145
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+
143152 # ####
144153 # #### `LinearAlgebra`
145154 # ####
@@ -301,6 +310,10 @@ Base.zero(x::Dual) = Dual(zero(x.value), zero(x.partial))
301310 # #### `ChainRulesCore`
302311 # ####
303312
313+ @testset " pass-through" begin
314+ @test ProjectTo (NoSuperType ()) === identity
315+ end
316+
304317 @testset " AbstractZero" begin
305318 pz = ProjectTo (ZeroTangent ())
306319 pz (0 ) == NoTangent ()
0 commit comments