1
1
# This file is a part of ArraysOfArrays.jl, licensed under the MIT License (MIT).
2
2
3
3
using ArraysOfArrays
4
- using Test
5
4
using StatsBase
6
5
using Statistics
6
+ using Test
7
7
8
8
using UnsafeArrays
9
9
@@ -103,7 +103,6 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
103
103
B1_copy = @inferred (copy (B1)); B3_copy = @inferred (copy (B3))
104
104
append! (B1_copy, B3_copy)
105
105
@test B1_copy. data == vcat (B1. data, B3. data)
106
-
107
106
end
108
107
109
108
@@ -112,14 +111,29 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
112
111
V2 = @inferred (VectorOfArrays (ref_AoA3 (Float32, 3 )))
113
112
V12 = vcat (V1, V2)
114
113
ind_style = @inferred (IndexStyle (V12))
114
+
115
115
@test ind_style == IndexLinear ()
116
+
116
117
for i in 1 : length (V12)
117
118
@test getindex (V12, i) == V12[i]
118
119
end
120
+
119
121
@test getindex (V12, 1 : length (V12)) == V12
120
-
122
+
121
123
@test @inferred (element_ptr (V12)) == V12. elem_ptr
122
124
125
+ getindex_of_UR = @inferred (Base. _getindex (ind_style, V12, 1 : length (V12)))
126
+ getindex_of_vector = @inferred (Base. _getindex (ind_style, V12, collect (1 : length (V12))))
127
+ @test getindex_of_UR == V12
128
+ @test getindex_of_vector == getindex_of_UR
129
+
130
+ VV = @inferred (VectorOfVectors {Float64} ())
131
+ data = @inferred (rand (5 ))
132
+ @inferred (push! (VV, data))
133
+ @test @inferred (getindex (VV, 1 )) == data
134
+ @test @inferred (size (getindex (VV, 1 ))) == (5 ,)
135
+
136
+
123
137
# # _view_reshape_spec not yet implemented ##
124
138
# V1_copy = copy(V1)
125
139
# V2_copy = copy(V2)
@@ -140,6 +154,54 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
140
154
141
155
end
142
156
157
+ @testset " indexing" begin
158
+ V1 = @inferred (VectorOfArrays (ref_AoA3 (Float32, 3 )))
159
+ V2 = @inferred (VectorOfArrays (ref_AoA3 (Float32, 3 )))
160
+ V12 = vcat (V1, V2)
161
+ ind_style = @inferred (IndexStyle (V12))
162
+ @test ind_style == IndexLinear ()
163
+ for i in 1 : length (V12)
164
+ @test getindex (V12, i) == V12[i]
165
+ end
166
+ @test getindex (V12, 1 : length (V12)) == V12
167
+
168
+ @test @inferred (element_ptr (V12)) == V12. elem_ptr
169
+
170
+ # # _view_reshape_spec not yet implemented ##
171
+ # V1_copy = copy(V1)
172
+ # V2_copy = copy(V2)
173
+ # @test setindex!(V1_copy, V1, 1) == V1
174
+ # setindex!(V2_copy, V2, 1)
175
+ # @test V2_copy[1] == V2_copy[2]
176
+
177
+ # # function mul(s) not yet implemented ##
178
+ # sizehint!(v12_copy, 2, (2,2,3))
179
+
180
+ # -------------------------------------------------------------------
181
+
182
+ zeroed_out = deepmap (x -> 0.0 , V12)
183
+ for i in zeroed_out
184
+ @test @inferred (zeros (size (i))) == i
185
+ end
186
+
187
+ # Not a good test of variable depth?
188
+ @test innermap (x -> 2 * x, V12) == deepmap (x -> 2 * x, V12)
189
+
190
+ f = x -> 0
191
+ A = @inferred (AbstractArray {AbstractArray{Float64, 3},1} ([rand (3 ,3 ,3 ), rand (3 ,3 ,3 ), rand (3 ,3 ,3 ), rand (3 ,3 ,3 )]))
192
+ A_inner = innermap (f,A)
193
+ A_deep = deepmap (f, A)
194
+
195
+ @test A_inner == A_deep
196
+
197
+ @test @inferred (size (A_inner)) == @inferred (size (A_deep))
198
+ @test innersize (A,1 ) == innersize (A,2 )
199
+ @test innersize (A,1 ) == innersize (A,3 )
200
+ for i in 1 : length (A_deep)
201
+ @test A_deep[i] == zeros (3 ,3 ,3 )
202
+ end
203
+ end
204
+
143
205
144
206
@testset " copy" begin
145
207
A = ref_AoA3 (Float32, 3 );
@@ -161,13 +223,28 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
161
223
162
224
163
225
@testset " examples" begin
164
- VA = VectorOfArrays {Float64, 2} ()
226
+ VA = @inferred (VectorOfArrays {Float64, 2} ())
227
+
228
+ @inferred (push! (VA, rand (2 , 3 )))
229
+ @inferred (push! (VA, rand (4 , 2 )))
230
+
231
+ @test @inferred (size (VA[1 ]) == (2 ,3 ))
232
+ @test @inferred (size (VA[2 ]) == (4 ,2 ))
165
233
166
- push! (VA, rand (2 , 3 ))
167
- push! (VA, rand (4 , 2 ))
234
+ # -------------------------------------------------------------------
235
+
236
+ VV = @inferred (VectorOfVectors {Float64} ())
237
+ d1 = @inferred (rand (5 ))
238
+ d2 = @inferred (rand (4 ))
239
+
240
+ @inferred (push! (VV, d1))
241
+ @inferred (push! (VV, d2))
242
+
243
+ @test VV[1 ] == d1
244
+ @test VV[2 ] == d2
168
245
169
- @test size (VA [1 ]) == (2 , 3 )
170
- @test size (VA [2 ]) == (4 ,2 )
246
+ @test @inferred ( size (VV [1 ])) == (5 , )
247
+ @test @inferred ( size (VV [2 ])) == (4 ,)
171
248
172
249
# -------------------------------------------------------------------
173
250
@@ -176,6 +253,7 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
176
253
177
254
@test @inferred (uview (VA)) == VA
178
255
@test @inferred (Base. unsafe_view (VA, 1 : size (VA)[1 ])) == VA
256
+
179
257
# -------------------------------------------------------------------
180
258
181
259
@@ -233,5 +311,12 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
233
311
@test flatview (result. a) === data. a
234
312
@test flatview (result. b) === data. b
235
313
@test flatview (result. c) === data. c
314
+
315
+ nestedV = @inferred (AbstractVector {AbstractArray{Float64, 4}} ([rand (4 ,2 ,3 ,1 ), rand (5 ,3 ,1 ,3 ), rand (6 ,4 ,3 ,1 ), rand (9 ,2 ,1 ,2 )]))
316
+ VoA1 = @inferred (convert (VectorOfArrays, nestedV))
317
+ @test @inferred (flatview (VoA1)) == VoA1. data
318
+ VoA2 = @inferred (convert (VectorOfArrays{Float32, 4 }, nestedV))
319
+ @test @inferred (map (Float32, VoA1. data)) == VoA2. data
320
+
236
321
end
237
322
end
0 commit comments