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