|
1 |
| -@testsuite "constructors" AT->begin |
2 |
| - @testset "constructors + similar" begin |
3 |
| - for T in supported_eltypes() |
4 |
| - B = AT{T}(undef, 10) |
5 |
| - @test B isa AT{T,1} |
6 |
| - @test size(B) == (10,) |
7 |
| - @test eltype(B) == T |
8 |
| - |
9 |
| - B = AT{T}(undef, 10, 10) |
10 |
| - @test B isa AT{T,2} |
11 |
| - @test size(B) == (10, 10) |
12 |
| - @test eltype(B) == T |
13 |
| - |
14 |
| - B = AT{T}(undef, (10, 10)) |
15 |
| - @test B isa AT{T,2} |
16 |
| - @test size(B) == (10, 10) |
17 |
| - @test eltype(B) == T |
18 |
| - |
19 |
| - B = similar(B, Int32, 11, 15) |
20 |
| - @test B isa AT{Int32,2} |
21 |
| - @test size(B) == (11, 15) |
22 |
| - @test eltype(B) == Int32 |
| 1 | +@testsuite "construct/direct" AT->begin |
| 2 | + for T in supported_eltypes() |
| 3 | + B = AT{T}(undef, 10) |
| 4 | + @test B isa AT{T,1} |
| 5 | + @test size(B) == (10,) |
| 6 | + @test eltype(B) == T |
23 | 7 |
|
24 |
| - B = similar(B, T) |
25 |
| - @test B isa AT{T,2} |
26 |
| - @test size(B) == (11, 15) |
27 |
| - @test eltype(B) == T |
| 8 | + B = AT{T}(undef, 10, 10) |
| 9 | + @test B isa AT{T,2} |
| 10 | + @test size(B) == (10, 10) |
| 11 | + @test eltype(B) == T |
| 12 | + |
| 13 | + B = AT{T}(undef, (10, 10)) |
| 14 | + @test B isa AT{T,2} |
| 15 | + @test size(B) == (10, 10) |
| 16 | + @test eltype(B) == T |
| 17 | + end |
| 18 | + |
| 19 | + # compare against Array |
| 20 | + for typs in [(), (Int,), (Int,1), (Int,2), (Float32,), (Float32,1), (Float32,2)], |
| 21 | + args in [(), (1,), (1,2), ((1,),), ((1,2),), |
| 22 | + (undef,), (undef, 1,), (undef, 1,2), (undef, (1,),), (undef, (1,2),), |
| 23 | + (Int,), (Int, 1,), (Int, 1,2), (Int, (1,),), (Int, (1,2),), |
| 24 | + ([1,2],), ([1 2],)] |
| 25 | + cpu = try |
| 26 | + Array{typs...}(args...) |
| 27 | + catch ex |
| 28 | + isa(ex, MethodError) || rethrow() |
| 29 | + nothing |
| 30 | + end |
| 31 | + |
| 32 | + gpu = try |
| 33 | + AT{typs...}(args...) |
| 34 | + catch ex |
| 35 | + isa(ex, MethodError) || rethrow() |
| 36 | + cpu == nothing || rethrow() |
| 37 | + nothing |
| 38 | + end |
| 39 | + |
| 40 | + if cpu == nothing |
| 41 | + @test gpu == nothing |
| 42 | + else |
| 43 | + @test typeof(cpu) == typeof(convert(Array, gpu)) |
| 44 | + end |
| 45 | + end |
| 46 | +end |
| 47 | + |
| 48 | +@testsuite "construct/similar" AT->begin |
| 49 | + for T in supported_eltypes() |
| 50 | + B = AT{T}(undef, 10) |
| 51 | + |
| 52 | + B = similar(B, Int32, 11, 15) |
| 53 | + @test B isa AT{Int32,2} |
| 54 | + @test size(B) == (11, 15) |
| 55 | + @test eltype(B) == Int32 |
| 56 | + |
| 57 | + B = similar(B, T) |
| 58 | + @test B isa AT{T,2} |
| 59 | + @test size(B) == (11, 15) |
| 60 | + @test eltype(B) == T |
| 61 | + |
| 62 | + B = similar(B, (5,)) |
| 63 | + @test B isa AT{T,1} |
| 64 | + @test size(B) == (5,) |
| 65 | + @test eltype(B) == T |
| 66 | + |
| 67 | + B = similar(B, 7) |
| 68 | + @test B isa AT{T,1} |
| 69 | + @test size(B) == (7,) |
| 70 | + @test eltype(B) == T |
28 | 71 |
|
29 |
| - B = similar(B, (5,)) |
30 |
| - @test B isa AT{T,1} |
31 |
| - @test size(B) == (5,) |
32 |
| - @test eltype(B) == T |
| 72 | + B = similar(AT{Int32}, (11, 15)) |
| 73 | + @test B isa AT{Int32,2} |
| 74 | + @test size(B) == (11, 15) |
| 75 | + @test eltype(B) == Int32 |
33 | 76 |
|
34 |
| - B = similar(B, 7) |
35 |
| - @test B isa AT{T,1} |
36 |
| - @test size(B) == (7,) |
37 |
| - @test eltype(B) == T |
| 77 | + B = similar(AT{T}, (5,)) |
| 78 | + @test B isa AT{T,1} |
| 79 | + @test size(B) == (5,) |
| 80 | + @test eltype(B) == T |
| 81 | + |
| 82 | + B = similar(AT{T}, 7) |
| 83 | + @test B isa AT{T,1} |
| 84 | + @test size(B) == (7,) |
| 85 | + @test eltype(B) == T |
| 86 | + |
| 87 | + B = similar(Broadcast.Broadcasted(*, (B, B)), T) |
| 88 | + @test B isa AT{T,1} |
| 89 | + @test size(B) == (7,) |
| 90 | + @test eltype(B) == T |
38 | 91 |
|
39 |
| - B = similar(AT{Int32}, (11, 15)) |
| 92 | + if VERSION >= v"1.5" |
| 93 | + B = similar(Broadcast.Broadcasted(*, (B, B)), Int32, (11, 15)) |
40 | 94 | @test B isa AT{Int32,2}
|
41 | 95 | @test size(B) == (11, 15)
|
42 | 96 | @test eltype(B) == Int32
|
43 |
| - |
44 |
| - B = similar(AT{T}, (5,)) |
45 |
| - @test B isa AT{T,1} |
46 |
| - @test size(B) == (5,) |
47 |
| - @test eltype(B) == T |
48 |
| - |
49 |
| - B = similar(AT{T}, 7) |
50 |
| - @test B isa AT{T,1} |
51 |
| - @test size(B) == (7,) |
52 |
| - @test eltype(B) == T |
53 |
| - |
54 |
| - B = similar(Broadcast.Broadcasted(*, (B, B)), T) |
55 |
| - @test B isa AT{T,1} |
56 |
| - @test size(B) == (7,) |
57 |
| - @test eltype(B) == T |
58 |
| - |
59 |
| - if VERSION >= v"1.5" |
60 |
| - B = similar(Broadcast.Broadcasted(*, (B, B)), Int32, (11, 15)) |
61 |
| - @test B isa AT{Int32,2} |
62 |
| - @test size(B) == (11, 15) |
63 |
| - @test eltype(B) == Int32 |
64 |
| - end |
65 | 97 | end
|
66 | 98 | end
|
| 99 | +end |
67 | 100 |
|
68 |
| - @testset "comparison against Array" begin |
69 |
| - for typs in [(), (Int,), (Int,1), (Int,2), (Float32,), (Float32,1), (Float32,2)], |
70 |
| - args in [(), (1,), (1,2), ((1,),), ((1,2),), |
71 |
| - (undef,), (undef, 1,), (undef, 1,2), (undef, (1,),), (undef, (1,2),), |
72 |
| - (Int,), (Int, 1,), (Int, 1,2), (Int, (1,),), (Int, (1,2),), |
73 |
| - ([1,2],), ([1 2],)] |
74 |
| - cpu = try |
75 |
| - Array{typs...}(args...) |
76 |
| - catch ex |
77 |
| - isa(ex, MethodError) || rethrow() |
78 |
| - nothing |
79 |
| - end |
80 |
| - |
81 |
| - gpu = try |
82 |
| - AT{typs...}(args...) |
83 |
| - catch ex |
84 |
| - isa(ex, MethodError) || rethrow() |
85 |
| - cpu == nothing || rethrow() |
86 |
| - nothing |
87 |
| - end |
88 |
| - |
89 |
| - if cpu == nothing |
90 |
| - @test gpu == nothing |
91 |
| - else |
92 |
| - @test typeof(cpu) == typeof(convert(Array, gpu)) |
93 |
| - end |
94 |
| - end |
| 101 | +@testsuite "construct/convenience" AT->begin |
| 102 | + for T in supported_eltypes() |
| 103 | + A = AT(rand(T, 3)) |
| 104 | + b = rand(T) |
| 105 | + fill!(A, b) |
| 106 | + @test A isa AT{T,1} |
| 107 | + @test Array(A) == fill(b, 3) |
| 108 | + |
| 109 | + A = zero(AT(rand(T, 2))) |
| 110 | + @test A isa AT{T,1} |
| 111 | + @test Array(A) == zero(rand(T, 2)) |
| 112 | + |
| 113 | + A = zero(AT(rand(T, 2, 2))) |
| 114 | + @test A isa AT{T,2} |
| 115 | + @test Array(A) == zero(rand(T, 2, 2)) |
| 116 | + |
| 117 | + A = zero(AT(rand(T, 2, 2, 2))) |
| 118 | + @test A isa AT{T,3} |
| 119 | + @test Array(A) == zero(rand(T, 2, 2, 2)) |
| 120 | + |
| 121 | + A = one(AT(rand(T, 2, 2))) |
| 122 | + @test A isa AT{T,2} |
| 123 | + @test Array(A) == one(rand(T, 2, 2)) |
| 124 | + |
| 125 | + A = oneunit(AT(rand(T, 2, 2))) |
| 126 | + @test A isa AT{T,2} |
| 127 | + @test Array(A) == oneunit(rand(T, 2, 2)) |
95 | 128 | end
|
96 | 129 | end
|
97 | 130 |
|
98 |
| -@testsuite "conversions" AT->begin |
| 131 | +@testsuite "construct/conversions" AT->begin |
99 | 132 | for T in supported_eltypes()
|
100 | 133 | Bc = round.(rand(10, 10) .* 10.0)
|
101 | 134 | B = AT{T}(Bc)
|
|
123 | 156 | end
|
124 | 157 | end
|
125 | 158 |
|
126 |
| -@testsuite "value constructors" AT->begin |
| 159 | +@testsuite "construct/uniformscaling" AT->begin |
127 | 160 | for T in supported_eltypes()
|
128 |
| - @test compare((a,b)->fill!(a, b), AT, rand(T, 3), rand(T)) |
129 |
| - |
130 | 161 | x = Matrix{T}(I, 4, 2)
|
131 | 162 |
|
132 | 163 | x1 = AT{T, 2}(I, 4, 2)
|
|
144 | 175 | end
|
145 | 176 | end
|
146 | 177 |
|
147 |
| -@testsuite "iterator constructors" AT->begin |
| 178 | +@testsuite "construct/iterator" AT->begin |
148 | 179 | for T in supported_eltypes()
|
149 | 180 | @test Array(AT(Fill(T(0), (10,)))) == Array(fill!(similar(AT{T}, (10,)), T(0)))
|
150 | 181 | @test Array(AT(Fill(T(0), (10, 10)))) == Array(fill!(similar(AT{T}, (10, 10)), T(0)))
|
|
0 commit comments