Skip to content

Commit 29a0250

Browse files
committed
Fix tests
1 parent 0e80852 commit 29a0250

File tree

1 file changed

+60
-63
lines changed

1 file changed

+60
-63
lines changed

test/test_CellArray.jl

Lines changed: 60 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,31 @@ test_metal = Metal.functional()
1515
array_types = ["CPU"]
1616
ArrayConstructors = [Array]
1717
CellArrayConstructors = [CPUCellArray]
18+
precision_types = [Float64]
1819
allowscalar_functions = Function[(x->x)]
1920
if test_cuda
2021
cuzeros = CUDA.zeros
2122
push!(array_types, "CUDA")
2223
push!(ArrayConstructors, CuArray)
2324
push!(CellArrayConstructors, CuCellArray)
2425
push!(allowscalar_functions, CUDA.allowscalar)
26+
push!(precision_types, Float64)
2527
end
2628
if test_amdgpu
2729
roczeros = AMDGPU.zeros
2830
push!(array_types, "AMDGPU")
2931
push!(ArrayConstructors, ROCArray)
3032
push!(CellArrayConstructors, ROCCellArray)
3133
push!(allowscalar_functions, AMDGPU.allowscalar)
34+
push!(precision_types, Float64)
3235
end
3336
if test_metal
3437
metalzeros = Metal.zeros
3538
push!(array_types, "Metal")
3639
push!(ArrayConstructors, MtlArray)
3740
push!(CellArrayConstructors, MtlCellArray)
3841
push!(allowscalar_functions, Metal.allowscalar)
42+
push!(precision_types, Float32)
3943
end
4044

4145
struct MyFieldArray{T} <: FieldArray{Tuple{2,2,2,2}, T, 4}
@@ -62,34 +66,29 @@ mutable struct MyMutableFieldArray{T} <: FieldArray{Tuple{2}, T, 1}
6266
yxxx::T
6367
end
6468

65-
const TEST_PRECISIONS = [Float32, Float64]
66-
for (array_type, Array, CellArray, allowscalar) in zip(array_types, ArrayConstructors, CellArrayConstructors, allowscalar_functions)
67-
for DataType in TEST_PRECISIONS
68-
(array_type == "Metal" && DataType == Float64) ? continue : nothing # Metal does not support Float64
69-
70-
@testset "$(basename(@__FILE__)) ($array_type arrays) (precision: $DataType)" begin
71-
@testset "1. CellArray allocation ($array_type arrays) (precision: $DataType)" begin
69+
@testset "$(basename(@__FILE__)) ($array_type arrays) (precision: $Float)" for (array_type, Array, CellArray, allowscalar, Float) in zip(array_types, ArrayConstructors, CellArrayConstructors, allowscalar_functions, precision_types)
70+
@testset "1. CellArray allocation ($array_type arrays) (precision: $(nameof(Float))" begin
7271
@testset "Number cells" begin
7372
dims = (2,3)
74-
A = CellArray{DataType}(undef, dims)
73+
A = CellArray{Float}(undef, dims)
7574
B = CellArrays.CellArray{Int32,prod(dims)}(Array, undef, dims...)
76-
C = CellArray{DataType,1}(undef, dims)
75+
C = CellArray{Float,1}(undef, dims)
7776
D = CellArray{Int32,4}(undef, dims)
7877
@test typeof(A.data) <: Array
7978
@test typeof(B.data) <: Array
8079
@test typeof(C.data) <: Array
8180
@test typeof(D.data) <: Array
82-
@test eltype(A.data) == DataType
81+
@test eltype(A.data) == Float
8382
@test eltype(B.data) == Int32
84-
@test eltype(C.data) == DataType
83+
@test eltype(C.data) == Float
8584
@test eltype(D.data) == Int32
86-
@test eltype(A) == DataType
85+
@test eltype(A) == Float
8786
@test eltype(B) == Int32
88-
@test eltype(C) == DataType
87+
@test eltype(C) == Float
8988
@test eltype(D) == Int32
90-
@test typeof(A) == CellArrays.CellArray{DataType, length(dims), 0, Array{eltype(A.data),_N}}
89+
@test typeof(A) == CellArrays.CellArray{Float, length(dims), 0, Array{eltype(A.data),_N}}
9190
@test typeof(B) == CellArrays.CellArray{Int32, length(dims), prod(dims), Array{eltype(B.data),_N}}
92-
@test typeof(C) == CellArrays.CellArray{DataType, length(dims), 1, Array{eltype(C.data),_N}}
91+
@test typeof(C) == CellArrays.CellArray{Float, length(dims), 1, Array{eltype(C.data),_N}}
9392
@test typeof(D) == CellArrays.CellArray{Int32, length(dims), 4, Array{eltype(D.data),_N}}
9493
@test length(A.data) == prod(dims)
9594
@test length(B.data) == prod(dims)
@@ -103,27 +102,27 @@ for DataType in TEST_PRECISIONS
103102
@testset "SArray cells" begin
104103
dims = (2,3)
105104
celldims = (3,4)
106-
T_DataType = SMatrix{celldims..., DataType, prod(celldims)}
105+
T_Float = SMatrix{celldims..., Float, prod(celldims)}
107106
T_Int32 = SMatrix{celldims..., Int32, prod(celldims)}
108-
A = CellArray{T_DataType}(undef, dims)
107+
A = CellArray{T_Float}(undef, dims)
109108
B = CellArrays.CellArray{T_Int32,prod(dims)}(Array, undef, dims...)
110-
C = CellArray{T_DataType,1}(undef, dims)
109+
C = CellArray{T_Float,1}(undef, dims)
111110
D = CellArray{T_Int32,4}(undef, dims)
112111
@test typeof(A.data) <: Array
113112
@test typeof(B.data) <: Array
114113
@test typeof(C.data) <: Array
115114
@test typeof(D.data) <: Array
116-
@test eltype(A.data) == DataType
115+
@test eltype(A.data) == Float
117116
@test eltype(B.data) == Int32
118-
@test eltype(C.data) == DataType
117+
@test eltype(C.data) == Float
119118
@test eltype(D.data) == Int32
120-
@test eltype(A) == T_DataType
119+
@test eltype(A) == T_Float
121120
@test eltype(B) == T_Int32
122-
@test eltype(C) == T_DataType
121+
@test eltype(C) == T_Float
123122
@test eltype(D) == T_Int32
124-
@test typeof(A) == CellArrays.CellArray{T_DataType, length(dims), 0, Array{eltype(A.data),_N}}
123+
@test typeof(A) == CellArrays.CellArray{T_Float, length(dims), 0, Array{eltype(A.data),_N}}
125124
@test typeof(B) == CellArrays.CellArray{T_Int32, length(dims), prod(dims), Array{eltype(B.data),_N}}
126-
@test typeof(C) == CellArrays.CellArray{T_DataType, length(dims), 1, Array{eltype(C.data),_N}}
125+
@test typeof(C) == CellArrays.CellArray{T_Float, length(dims), 1, Array{eltype(C.data),_N}}
127126
@test typeof(D) == CellArrays.CellArray{T_Int32, length(dims), 4, Array{eltype(D.data),_N}}
128127
@test length(A.data) == prod(dims)*prod(celldims)
129128
@test length(B.data) == prod(dims)*prod(celldims)
@@ -137,27 +136,27 @@ for DataType in TEST_PRECISIONS
137136
@testset "FieldArray cells" begin
138137
dims = (2,3)
139138
celldims = size(MyFieldArray)
140-
T_DataType = MyFieldArray{DataType}
139+
T_Float = MyFieldArray{Float}
141140
T_Int32 = MyFieldArray{Int32}
142-
A = CellArray{T_DataType}(undef, dims)
141+
A = CellArray{T_Float}(undef, dims)
143142
B = CellArrays.CellArray{T_Int32,prod(dims)}(Array, undef, dims...)
144-
C = CellArray{T_DataType,1}(undef, dims)
143+
C = CellArray{T_Float,1}(undef, dims)
145144
D = CellArray{T_Int32,4}(undef, dims)
146145
@test typeof(A.data) <: Array
147146
@test typeof(B.data) <: Array
148147
@test typeof(C.data) <: Array
149148
@test typeof(D.data) <: Array
150-
@test eltype(A.data) == DataType
149+
@test eltype(A.data) == Float
151150
@test eltype(B.data) == Int32
152-
@test eltype(C.data) == DataType
151+
@test eltype(C.data) == Float
153152
@test eltype(D.data) == Int32
154-
@test eltype(A) == T_DataType
153+
@test eltype(A) == T_Float
155154
@test eltype(B) == T_Int32
156-
@test eltype(C) == T_DataType
155+
@test eltype(C) == T_Float
157156
@test eltype(D) == T_Int32
158-
@test typeof(A) == CellArrays.CellArray{T_DataType, length(dims), 0, Array{eltype(A.data),_N}}
157+
@test typeof(A) == CellArrays.CellArray{T_Float, length(dims), 0, Array{eltype(A.data),_N}}
159158
@test typeof(B) == CellArrays.CellArray{T_Int32, length(dims), prod(dims), Array{eltype(B.data),_N}}
160-
@test typeof(C) == CellArrays.CellArray{T_DataType, length(dims), 1, Array{eltype(C.data),_N}}
159+
@test typeof(C) == CellArrays.CellArray{T_Float, length(dims), 1, Array{eltype(C.data),_N}}
161160
@test typeof(D) == CellArrays.CellArray{T_Int32, length(dims), 4, Array{eltype(D.data),_N}}
162161
@test length(A.data) == prod(dims)*prod(celldims)
163162
@test length(B.data) == prod(dims)*prod(celldims)
@@ -172,17 +171,17 @@ for DataType in TEST_PRECISIONS
172171
@testset "2. functions ($array_type arrays)" begin
173172
dims = (2,3)
174173
celldims = (3,4) # Needs to be compatible for matrix multiplication!
175-
T_DataType = SMatrix{celldims..., DataType, prod(celldims)}
174+
T_Float = SMatrix{celldims..., Float, prod(celldims)}
176175
T_Int32 = SMatrix{celldims..., Int32, prod(celldims)}
177-
T2_DataType = MyFieldArray{DataType}
176+
T2_DataType = MyFieldArray{Float}
178177
T2_Int32 = MyFieldArray{Int32}
179-
A = CellArray{DataType}(undef, dims)
178+
A = CellArray{Float}(undef, dims)
180179
B = CellArrays.CellArray{Int32,prod(dims)}(Array, undef, dims)
181-
C = CellArray{T_DataType}(undef, dims)
180+
C = CellArray{T_Float}(undef, dims)
182181
D = CellArray{T_Int32,prod(dims)}(undef, dims)
183182
E = CellArray{T2_DataType}(undef, dims)
184183
F = CellArray{T2_Int32,prod(dims)}(undef, dims)
185-
G = CellArray{T_DataType,1}(undef, dims)
184+
G = CellArray{T_Float,1}(undef, dims)
186185
H = CellArray{T_Int32,4}(undef, dims)
187186
@testset "size" begin
188187
@test size(A) == dims
@@ -216,11 +215,11 @@ for DataType in TEST_PRECISIONS
216215
allowscalar() do
217216
fill!(A, 9); @test all(Base.Array(A.data) .== 9.0)
218217
fill!(B, 9.0); @test all(Base.Array(B.data) .== 9)
219-
fill!(C, (1:length(eltype(C)))); @test all(C .== (T_DataType(1:length(eltype(C))) for i=1:dims[1], j=1:dims[2]))
218+
fill!(C, (1:length(eltype(C)))); @test all(C .== (T_Float(1:length(eltype(C))) for i=1:dims[1], j=1:dims[2]))
220219
fill!(D, (1:length(eltype(D)))); @test all(D .== (T_Int32(1:length(eltype(D))) for i=1:dims[1], j=1:dims[2]))
221220
fill!(E, (1:length(eltype(E)))); @test all(E .== (T2_DataType(1:length(eltype(E))) for i=1:dims[1], j=1:dims[2]))
222221
fill!(F, (1:length(eltype(F)))); @test all(F .== (T2_Int32(1:length(eltype(F))) for i=1:dims[1], j=1:dims[2]))
223-
fill!(G, (1:length(eltype(G)))); @test all(G .== (T_DataType(1:length(eltype(G))) for i=1:dims[1], j=1:dims[2]))
222+
fill!(G, (1:length(eltype(G)))); @test all(G .== (T_Float(1:length(eltype(G))) for i=1:dims[1], j=1:dims[2]))
224223
fill!(H, (1:length(eltype(H)))); @test all(H .== (T_Int32(1:length(eltype(H))) for i=1:dims[1], j=1:dims[2]))
225224
end
226225
end
@@ -229,19 +228,19 @@ for DataType in TEST_PRECISIONS
229228
A.data.=0; B.data.=0; C.data.=0; D.data.=0; E.data.=0; F.data.=0; G.data.=0; H.data.=0;
230229
A[2,2:3] .= 9
231230
B[2,2:3] .= 9.0
232-
C[2,2:3] .= (T_DataType(1:length(T_DataType)), T_DataType(1:length(T_DataType)))
231+
C[2,2:3] .= (T_Float(1:length(T_Float)), T_Float(1:length(T_Float)))
233232
D[2,2:3] .= (T_Int32(1:length(T_Int32)), T_Int32(1:length(T_Int32)))
234233
E[2,2:3] .= (T2_DataType(1:length(T2_DataType)), T2_DataType(1:length(T2_DataType)))
235234
F[2,2:3] .= (T2_Int32(1:length(T2_Int32)), T2_Int32(1:length(T2_Int32)))
236-
G[2,2:3] .= (T_DataType(1:length(T_DataType)), T_DataType(1:length(T_DataType)))
235+
G[2,2:3] .= (T_Float(1:length(T_Float)), T_Float(1:length(T_Float)))
237236
H[2,2:3] .= (T_Int32(1:length(T_Int32)), T_Int32(1:length(T_Int32)))
238237
@test all(A[2,2:3] .== 9.0)
239238
@test all(B[2,2:3] .== 9)
240-
@test all(C[2,2:3] .== (T_DataType(1:length(T_DataType)), T_DataType(1:length(T_DataType))))
239+
@test all(C[2,2:3] .== (T_Float(1:length(T_Float)), T_Float(1:length(T_Float))))
241240
@test all(D[2,2:3] .== (T_Int32(1:length(T_Int32)), T_Int32(1:length(T_Int32))))
242241
@test all(E[2,2:3] .== (T2_DataType(1:length(T2_DataType)), T2_DataType(1:length(T2_DataType))))
243242
@test all(F[2,2:3] .== (T2_Int32(1:length(T2_Int32)), T2_Int32(1:length(T2_Int32))))
244-
@test all(G[2,2:3] .== (T_DataType(1:length(T_DataType)), T_DataType(1:length(T_DataType))))
243+
@test all(G[2,2:3] .== (T_Float(1:length(T_Float)), T_Float(1:length(T_Float))))
245244
@test all(H[2,2:3] .== (T_Int32(1:length(T_Int32)), T_Int32(1:length(T_Int32))))
246245
end
247246
end;
@@ -326,37 +325,35 @@ for DataType in TEST_PRECISIONS
326325
@testset "3. Exceptions ($array_type arrays)" begin
327326
dims = (2,3)
328327
celldims = (3,4)
329-
T_DataType = SMatrix{celldims..., DataType, prod(celldims)}
328+
T_Float = SMatrix{celldims..., Float, prod(celldims)}
330329
T_Int32 = SMatrix{celldims..., Int32, prod(celldims)}
331-
T2_DataType = MyFieldArray{DataType}
330+
T2_DataType = MyFieldArray{Float}
332331
T2_Int32 = MyFieldArray{Int32}
333-
A = CellArray{DataType}(undef, dims)
332+
A = CellArray{Float}(undef, dims)
334333
B = CellArrays.CellArray{Int32,prod(dims)}(Array, undef, dims)
335-
C = CellArray{T_DataType}(undef, dims)
334+
C = CellArray{T_Float}(undef, dims)
336335
D = CellArray{T_Int32,prod(dims)}(undef, dims)
337336
E = CellArray{T2_DataType}(undef, dims)
338337
F = CellArray{T2_Int32,prod(dims)}(undef, dims)
339-
G = CellArray{T_DataType,1}(undef, dims)
338+
G = CellArray{T_Float,1}(undef, dims)
340339
H = CellArray{T_Int32,4}(undef, dims)
341340
@test_throws TypeError CellArray{Array}(undef, dims) # Error: TypeError (celltype T is restricted to `Cell` in the package)
342-
@test_throws TypeError CellArray{MMatrix{celldims..., DataType, prod(celldims)}}(undef, dims) # ...
341+
@test_throws TypeError CellArray{MMatrix{celldims..., Float, prod(celldims)}}(undef, dims) # ...
343342
@test_throws ArgumentError CellArray{MyMutableFieldArray}(undef, dims) # Error: the celltype, `T`, must be a bitstype.
344-
@test_throws IncoherentArgumentError CellArrays.CellArray{DataType,2,0}(similar(A.data, Int64), A.dims) # Error: eltype(data) must match eltype(T).
345-
@test_throws IncoherentArgumentError CellArrays.CellArray{Int32,2,prod(dims)}(similar(B.data, DataType), B.dims) # ...
346-
@test_throws IncoherentArgumentError CellArrays.CellArray{T_DataType,2,0}(similar(C.data, Int64), C.dims) # ...
343+
@test_throws IncoherentArgumentError CellArrays.CellArray{Float,2,0}(similar(A.data, Int64), A.dims) # Error: eltype(data) must match eltype(T).
344+
@test_throws IncoherentArgumentError CellArrays.CellArray{Int32,2,prod(dims)}(similar(B.data, Float), B.dims) # ...
345+
@test_throws IncoherentArgumentError CellArrays.CellArray{T_Float,2,0}(similar(C.data, Int64), C.dims) # ...
347346
@test_throws IncoherentArgumentError CellArrays.CellArray{T_Int32,2,prod(dims)}(similar(D.data, T_Int32), D.dims) # ...
348347
@test_throws IncoherentArgumentError CellArrays.CellArray{T2_DataType,2,0}(similar(E.data, Int64), E.dims) # ...
349348
@test_throws IncoherentArgumentError CellArrays.CellArray{T2_Int32,2,prod(dims)}(similar(F.data, T2_Int32), F.dims) # ...
350-
@test_throws IncoherentArgumentError CellArrays.CellArray{T_DataType,2,1}(similar(G.data, Int64), G.dims) # ...
349+
@test_throws IncoherentArgumentError CellArrays.CellArray{T_Float,2,1}(similar(G.data, Int64), G.dims) # ...
351350
@test_throws IncoherentArgumentError CellArrays.CellArray{T_Int32,2,4}(similar(H.data, T_Int32), H.dims) # ...
352-
@test_throws MethodError CellArrays.CellArray{DataType,2,0}(A.data[:], A.dims) # Error: ndims(data) must be 3.
353-
@test_throws MethodError CellArrays.CellArray{T_DataType,2,0}(C.data[:], C.dims) # Error: ...
351+
@test_throws MethodError CellArrays.CellArray{Float,2,0}(A.data[:], A.dims) # Error: ndims(data) must be 3.
352+
@test_throws MethodError CellArrays.CellArray{T_Float,2,0}(C.data[:], C.dims) # Error: ...
354353
@test_throws MethodError CellArrays.CellArray{T2_DataType,2,0}(E.data[:], E.dims) # Error: ...
355-
@test_throws IncoherentArgumentError CellArrays.CellArray{DataType,2,0}(similar(A.data, DataType, (1,2,1)), A.dims) # Error: size(data) must match (blocklen, prod(size(T), ceil(prod(dims)/blocklen)).
356-
@test_throws IncoherentArgumentError CellArrays.CellArray{T_DataType,2,0}(similar(C.data, DataType, (1,2,1)), C.dims) # ...
357-
@test_throws IncoherentArgumentError CellArrays.CellArray{T2_DataType,2,0}(similar(E.data, DataType, (1,2,1)), E.dims) # ...
358-
@test_throws IncoherentArgumentError CellArrays.CellArray{SMatrix{(4,5)..., DataType, prod((4,5))},2,0}(C.data, C.dims) # ...
354+
@test_throws IncoherentArgumentError CellArrays.CellArray{Float,2,0}(similar(A.data, Float, (1,2,1)), A.dims) # Error: size(data) must match (blocklen, prod(size(T), ceil(prod(dims)/blocklen)).
355+
@test_throws IncoherentArgumentError CellArrays.CellArray{T_Float,2,0}(similar(C.data, Float, (1,2,1)), C.dims) # ...
356+
@test_throws IncoherentArgumentError CellArrays.CellArray{T2_DataType,2,0}(similar(E.data, Float, (1,2,1)), E.dims) # ...
357+
@test_throws IncoherentArgumentError CellArrays.CellArray{SMatrix{(4,5)..., Float, prod((4,5))},2,0}(C.data, C.dims) # ...
359358
end;
360-
end;
361-
362-
end end
359+
end;

0 commit comments

Comments
 (0)