@@ -15,27 +15,31 @@ test_metal = Metal.functional()
15
15
array_types = [" CPU" ]
16
16
ArrayConstructors = [Array]
17
17
CellArrayConstructors = [CPUCellArray]
18
+ precision_types = [Float64]
18
19
allowscalar_functions = Function[(x-> x)]
19
20
if test_cuda
20
21
cuzeros = CUDA. zeros
21
22
push! (array_types, " CUDA" )
22
23
push! (ArrayConstructors, CuArray)
23
24
push! (CellArrayConstructors, CuCellArray)
24
25
push! (allowscalar_functions, CUDA. allowscalar)
26
+ push! (precision_types, Float64)
25
27
end
26
28
if test_amdgpu
27
29
roczeros = AMDGPU. zeros
28
30
push! (array_types, " AMDGPU" )
29
31
push! (ArrayConstructors, ROCArray)
30
32
push! (CellArrayConstructors, ROCCellArray)
31
33
push! (allowscalar_functions, AMDGPU. allowscalar)
34
+ push! (precision_types, Float64)
32
35
end
33
36
if test_metal
34
37
metalzeros = Metal. zeros
35
38
push! (array_types, " Metal" )
36
39
push! (ArrayConstructors, MtlArray)
37
40
push! (CellArrayConstructors, MtlCellArray)
38
41
push! (allowscalar_functions, Metal. allowscalar)
42
+ push! (precision_types, Float32)
39
43
end
40
44
41
45
struct MyFieldArray{T} <: FieldArray{Tuple{2,2,2,2}, T, 4}
@@ -62,34 +66,29 @@ mutable struct MyMutableFieldArray{T} <: FieldArray{Tuple{2}, T, 1}
62
66
yxxx:: T
63
67
end
64
68
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
72
71
@testset " Number cells" begin
73
72
dims = (2 ,3 )
74
- A = CellArray {DataType } (undef, dims)
73
+ A = CellArray {Float } (undef, dims)
75
74
B = CellArrays. CellArray {Int32,prod(dims)} (Array, undef, dims... )
76
- C = CellArray {DataType ,1} (undef, dims)
75
+ C = CellArray {Float ,1} (undef, dims)
77
76
D = CellArray {Int32,4} (undef, dims)
78
77
@test typeof (A. data) <: Array
79
78
@test typeof (B. data) <: Array
80
79
@test typeof (C. data) <: Array
81
80
@test typeof (D. data) <: Array
82
- @test eltype (A. data) == DataType
81
+ @test eltype (A. data) == Float
83
82
@test eltype (B. data) == Int32
84
- @test eltype (C. data) == DataType
83
+ @test eltype (C. data) == Float
85
84
@test eltype (D. data) == Int32
86
- @test eltype (A) == DataType
85
+ @test eltype (A) == Float
87
86
@test eltype (B) == Int32
88
- @test eltype (C) == DataType
87
+ @test eltype (C) == Float
89
88
@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}}
91
90
@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}}
93
92
@test typeof (D) == CellArrays. CellArray{Int32, length (dims), 4 , Array{eltype (D. data),_N}}
94
93
@test length (A. data) == prod (dims)
95
94
@test length (B. data) == prod (dims)
@@ -103,27 +102,27 @@ for DataType in TEST_PRECISIONS
103
102
@testset " SArray cells" begin
104
103
dims = (2 ,3 )
105
104
celldims = (3 ,4 )
106
- T_DataType = SMatrix{celldims... , DataType , prod (celldims)}
105
+ T_Float = SMatrix{celldims... , Float , prod (celldims)}
107
106
T_Int32 = SMatrix{celldims... , Int32, prod (celldims)}
108
- A = CellArray {T_DataType } (undef, dims)
107
+ A = CellArray {T_Float } (undef, dims)
109
108
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)
111
110
D = CellArray {T_Int32,4} (undef, dims)
112
111
@test typeof (A. data) <: Array
113
112
@test typeof (B. data) <: Array
114
113
@test typeof (C. data) <: Array
115
114
@test typeof (D. data) <: Array
116
- @test eltype (A. data) == DataType
115
+ @test eltype (A. data) == Float
117
116
@test eltype (B. data) == Int32
118
- @test eltype (C. data) == DataType
117
+ @test eltype (C. data) == Float
119
118
@test eltype (D. data) == Int32
120
- @test eltype (A) == T_DataType
119
+ @test eltype (A) == T_Float
121
120
@test eltype (B) == T_Int32
122
- @test eltype (C) == T_DataType
121
+ @test eltype (C) == T_Float
123
122
@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}}
125
124
@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}}
127
126
@test typeof (D) == CellArrays. CellArray{T_Int32, length (dims), 4 , Array{eltype (D. data),_N}}
128
127
@test length (A. data) == prod (dims)* prod (celldims)
129
128
@test length (B. data) == prod (dims)* prod (celldims)
@@ -137,27 +136,27 @@ for DataType in TEST_PRECISIONS
137
136
@testset " FieldArray cells" begin
138
137
dims = (2 ,3 )
139
138
celldims = size (MyFieldArray)
140
- T_DataType = MyFieldArray{DataType }
139
+ T_Float = MyFieldArray{Float }
141
140
T_Int32 = MyFieldArray{Int32}
142
- A = CellArray {T_DataType } (undef, dims)
141
+ A = CellArray {T_Float } (undef, dims)
143
142
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)
145
144
D = CellArray {T_Int32,4} (undef, dims)
146
145
@test typeof (A. data) <: Array
147
146
@test typeof (B. data) <: Array
148
147
@test typeof (C. data) <: Array
149
148
@test typeof (D. data) <: Array
150
- @test eltype (A. data) == DataType
149
+ @test eltype (A. data) == Float
151
150
@test eltype (B. data) == Int32
152
- @test eltype (C. data) == DataType
151
+ @test eltype (C. data) == Float
153
152
@test eltype (D. data) == Int32
154
- @test eltype (A) == T_DataType
153
+ @test eltype (A) == T_Float
155
154
@test eltype (B) == T_Int32
156
- @test eltype (C) == T_DataType
155
+ @test eltype (C) == T_Float
157
156
@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}}
159
158
@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}}
161
160
@test typeof (D) == CellArrays. CellArray{T_Int32, length (dims), 4 , Array{eltype (D. data),_N}}
162
161
@test length (A. data) == prod (dims)* prod (celldims)
163
162
@test length (B. data) == prod (dims)* prod (celldims)
@@ -172,17 +171,17 @@ for DataType in TEST_PRECISIONS
172
171
@testset " 2. functions ($array_type arrays)" begin
173
172
dims = (2 ,3 )
174
173
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)}
176
175
T_Int32 = SMatrix{celldims... , Int32, prod (celldims)}
177
- T2_DataType = MyFieldArray{DataType }
176
+ T2_DataType = MyFieldArray{Float }
178
177
T2_Int32 = MyFieldArray{Int32}
179
- A = CellArray {DataType } (undef, dims)
178
+ A = CellArray {Float } (undef, dims)
180
179
B = CellArrays. CellArray {Int32,prod(dims)} (Array, undef, dims)
181
- C = CellArray {T_DataType } (undef, dims)
180
+ C = CellArray {T_Float } (undef, dims)
182
181
D = CellArray {T_Int32,prod(dims)} (undef, dims)
183
182
E = CellArray {T2_DataType} (undef, dims)
184
183
F = CellArray {T2_Int32,prod(dims)} (undef, dims)
185
- G = CellArray {T_DataType ,1} (undef, dims)
184
+ G = CellArray {T_Float ,1} (undef, dims)
186
185
H = CellArray {T_Int32,4} (undef, dims)
187
186
@testset " size" begin
188
187
@test size (A) == dims
@@ -216,11 +215,11 @@ for DataType in TEST_PRECISIONS
216
215
allowscalar () do
217
216
fill! (A, 9 ); @test all (Base. Array (A. data) .== 9.0 )
218
217
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 ]))
220
219
fill! (D, (1 : length (eltype (D)))); @test all (D .== (T_Int32 (1 : length (eltype (D))) for i= 1 : dims[1 ], j= 1 : dims[2 ]))
221
220
fill! (E, (1 : length (eltype (E)))); @test all (E .== (T2_DataType (1 : length (eltype (E))) for i= 1 : dims[1 ], j= 1 : dims[2 ]))
222
221
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 ]))
224
223
fill! (H, (1 : length (eltype (H)))); @test all (H .== (T_Int32 (1 : length (eltype (H))) for i= 1 : dims[1 ], j= 1 : dims[2 ]))
225
224
end
226
225
end
@@ -229,19 +228,19 @@ for DataType in TEST_PRECISIONS
229
228
A. data.= 0 ; B. data.= 0 ; C. data.= 0 ; D. data.= 0 ; E. data.= 0 ; F. data.= 0 ; G. data.= 0 ; H. data.= 0 ;
230
229
A[2 ,2 : 3 ] .= 9
231
230
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 )))
233
232
D[2 ,2 : 3 ] .= (T_Int32 (1 : length (T_Int32)), T_Int32 (1 : length (T_Int32)))
234
233
E[2 ,2 : 3 ] .= (T2_DataType (1 : length (T2_DataType)), T2_DataType (1 : length (T2_DataType)))
235
234
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 )))
237
236
H[2 ,2 : 3 ] .= (T_Int32 (1 : length (T_Int32)), T_Int32 (1 : length (T_Int32)))
238
237
@test all (A[2 ,2 : 3 ] .== 9.0 )
239
238
@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 ))))
241
240
@test all (D[2 ,2 : 3 ] .== (T_Int32 (1 : length (T_Int32)), T_Int32 (1 : length (T_Int32))))
242
241
@test all (E[2 ,2 : 3 ] .== (T2_DataType (1 : length (T2_DataType)), T2_DataType (1 : length (T2_DataType))))
243
242
@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 ))))
245
244
@test all (H[2 ,2 : 3 ] .== (T_Int32 (1 : length (T_Int32)), T_Int32 (1 : length (T_Int32))))
246
245
end
247
246
end ;
@@ -326,37 +325,35 @@ for DataType in TEST_PRECISIONS
326
325
@testset " 3. Exceptions ($array_type arrays)" begin
327
326
dims = (2 ,3 )
328
327
celldims = (3 ,4 )
329
- T_DataType = SMatrix{celldims... , DataType , prod (celldims)}
328
+ T_Float = SMatrix{celldims... , Float , prod (celldims)}
330
329
T_Int32 = SMatrix{celldims... , Int32, prod (celldims)}
331
- T2_DataType = MyFieldArray{DataType }
330
+ T2_DataType = MyFieldArray{Float }
332
331
T2_Int32 = MyFieldArray{Int32}
333
- A = CellArray {DataType } (undef, dims)
332
+ A = CellArray {Float } (undef, dims)
334
333
B = CellArrays. CellArray {Int32,prod(dims)} (Array, undef, dims)
335
- C = CellArray {T_DataType } (undef, dims)
334
+ C = CellArray {T_Float } (undef, dims)
336
335
D = CellArray {T_Int32,prod(dims)} (undef, dims)
337
336
E = CellArray {T2_DataType} (undef, dims)
338
337
F = CellArray {T2_Int32,prod(dims)} (undef, dims)
339
- G = CellArray {T_DataType ,1} (undef, dims)
338
+ G = CellArray {T_Float ,1} (undef, dims)
340
339
H = CellArray {T_Int32,4} (undef, dims)
341
340
@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) # ...
343
342
@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) # ...
347
346
@test_throws IncoherentArgumentError CellArrays. CellArray {T_Int32,2,prod(dims)} (similar (D. data, T_Int32), D. dims) # ...
348
347
@test_throws IncoherentArgumentError CellArrays. CellArray {T2_DataType,2,0} (similar (E. data, Int64), E. dims) # ...
349
348
@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) # ...
351
350
@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: ...
354
353
@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) # ...
359
358
end ;
360
- end ;
361
-
362
- end end
359
+ end ;
0 commit comments