@@ -18,7 +18,7 @@ using OffsetArrays, BenchmarkTools
18
18
@test ProjectTo (big (1.0 ))(2 ) === 2
19
19
end
20
20
21
- @testset " Base: arrays" begin
21
+ @testset " Base: arrays of numbers " begin
22
22
pvec3 = ProjectTo ([1 ,2 ,3 ])
23
23
@test pvec3 (1.0 : 3.0 ) === 1.0 : 3.0
24
24
@test pvec3 (1 : 3 ) == 1.0 : 3.0 # would prefer ===, map(Float64, dx) would do that, not important
@@ -35,17 +35,30 @@ using OffsetArrays, BenchmarkTools
35
35
@test pmat ([1 2 ; 3 4 ]' ) isa Matrix{ComplexF64} # broadcast type change
36
36
37
37
pmat2 = ProjectTo (rand (2 ,2 )' )
38
- @test pmat2 ([1 2 ; 3 4.0 + 5im ]) isa Matrix # adjoint matrices are not preserved
38
+ @test pmat2 ([1 2 ; 3 4.0 + 5im ]) isa Matrix # adjoint matrices are not re-created
39
39
40
- # arrays of arrays
40
+ prow = ProjectTo ([1im 2 3im ])
41
+ @test prow (transpose ([1 , 2 , 3 + 4.0im ])) == [1 2 3 + 4im ]
42
+ @test prow (transpose ([1 , 2 , 3 + 4.0im ])) isa Matrix # row vectors may not pass through
43
+ @test prow (adjoint ([1 , 2 , 3 + 5im ])) == [1 2 3 - 5im ]
44
+ @test prow (adjoint ([1 , 2 , 3 ])) isa Matrix
45
+ end
46
+
47
+ @testset " Base: arrays of arrays, etc" begin
41
48
pvecvec = ProjectTo ([[1 ,2 ], [3 ,4 ,5 ]])
42
49
@test pvecvec ([1 : 2 , 3 : 5 ])[1 ] == 1 : 2
43
50
@test pvecvec ([[1 ,2 + 3im ], [4 + 5im ,6 ,7 ]])[2 ] == [4 ,6 ,7 ]
44
51
@test pvecvec (hcat ([1 : 2 , hcat (3 : 5 )]))[2 ] isa Vector # reshape inner & outer
45
52
53
+ pvecvec2 = ProjectTo (reshape (Any[[1 2 ], [3 4 5 ]],1 ,2 )) # a row of rows
54
+ y1 = pvecvec2 ([[1 ,2 ], [3 ,4 ,5 ]]' )
55
+ @test y1[1 ] == [1 2 ]
56
+ @test ! (y1 isa Adjoint) && ! (y1[1 ] isa Adjoint)
57
+
46
58
# arrays of unknown things
47
59
@test ProjectTo ([:x , :y ])(1 : 2 ) === 1 : 2 # no element handling,
48
60
@test ProjectTo ([:x , :y ])(reshape (1 : 2 ,2 ,1 ,1 )) == 1 : 2 # but still reshapes container
61
+
49
62
@test ProjectTo (Any[1 , 2 ])(1 : 2 ) == [1.0 , 2.0 ] # projects each number.
50
63
@test Tuple (ProjectTo (Any[1 , 2 + 3im ])(1 : 2 )) === (1.0 , 2.0 + 0.0im )
51
64
@test ProjectTo (Any[true , false ]) isa ProjectTo{NoTangent}
@@ -94,6 +107,15 @@ using OffsetArrays, BenchmarkTools
94
107
@test padj_complex ([4 5 6 + 7im ]) == [4 5 6 + 7im ]
95
108
@test padj_complex (transpose ([4 , 5 , 6 + 7im ])) == [4 5 6 + 7im ]
96
109
@test padj_complex (adjoint ([4 , 5 , 6 + 7im ])) == [4 5 6 - 7im ]
110
+
111
+ # evil test case
112
+ xs = adjoint (Any[Any[1 ,2 ,3 ], Any[4 + im,5 - im,6 + im,7 - im]])
113
+ pvecvec3 = ProjectTo (xs)
114
+ @test pvecvec3 (xs)[1 ] == [1 2 3 ]
115
+ @test pvecvec3 (xs)[2 ] isa Adjoint{ComplexF64, <: Vector }
116
+ @test_broken pvecvec3 (collect (xs))[1 ] == [1 2 3 ]
117
+ ys = permutedims ([[1 2 3 + im], [4 5 6 7 ]])
118
+ @test_broken pvecvec3 (ys)[1 ] == [1 2 3 ]
97
119
end
98
120
99
121
@testset " LinearAlgebra: structured matrices" begin
@@ -242,7 +264,7 @@ using OffsetArrays, BenchmarkTools
242
264
243
265
padj = ProjectTo (adjoint (rand (10 ^ 3 )))
244
266
@test 0 == @ballocated $ padj (dx) setup= (dx= adjoint (rand (10 ^ 3 )))
245
- @test 0 == @ballocated $ padj (dx) setup= (dx= transpose (rand (10 ^ 3 )))
267
+ @test_broken 0 == @ballocated $ padj (dx) setup= (dx= transpose (rand (10 ^ 3 )))
246
268
247
269
@test 0 == @ballocated ProjectTo (x' )(dx' ) setup= (x= rand (10 ^ 3 ); dx= rand (10 ^ 3 ))
248
270
0 commit comments