@@ -231,76 +231,9 @@ mutable struct TestAbstractArray end
231
231
232
232
# # Tests for the abstract array interfaces with minimally defined array types
233
233
234
- # A custom linear fast array type with 24 elements that doesn't rely upon Array storage
235
- mutable struct T24Linear{T,N,dims} <: AbstractArray{T,N}
236
- v1:: T ; v2:: T ; v3:: T ; v4:: T ; v5:: T ; v6:: T ; v7:: T ; v8:: T
237
- v9:: T ; v10:: T ; v11:: T ; v12:: T ; v13:: T ; v14:: T ; v15:: T ; v16:: T
238
- v17:: T ; v18:: T ; v19:: T ; v20:: T ; v21:: T ; v22:: T ; v23:: T ; v24:: T
239
- T24Linear {T,N,d} () where {T,N,d} =
240
- (prod (d) == 24 || throw (DimensionMismatch (" T24Linear must have 24 elements" )); new ())
241
- function T24Linear {T,N,d} (v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,
242
- v13,v14,v15,v16,v17,v18,v19,v20,v21,v22,v23,v24) where {T,N,d}
243
- prod (d) == 24 || throw (DimensionMismatch (" T24Linear must have 24 elements" ))
244
- new (v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20,v21,v22,v23,v24)
245
- end
246
- end
247
-
248
- T24Linear (:: Type{T} , dims:: Int... ) where T = T24Linear (T, dims)
249
- T24Linear (:: Type{T} , dims:: NTuple{N,Int} ) where {T,N} = T24Linear {T,N,dims} ()
250
-
251
- T24Linear ( X:: AbstractArray{T,N} ) where {T,N } = T24Linear {T,N} (X)
252
- T24Linear {T } (X:: AbstractArray{_,N} ) where {T,N,_} = T24Linear {T,N} (X)
253
- T24Linear {T,N} (X:: AbstractArray ) where {T,N } = T24Linear {T,N,size(X)} (X... )
254
-
255
- Base. size (:: T24Linear{T,N,dims} ) where {T,N,dims} = dims
256
- import Base: IndexLinear
257
- Base. IndexStyle (:: Type{A} ) where {A<: T24Linear } = IndexLinear ()
258
- Base. getindex (A:: T24Linear , i:: Int ) = getfield (A, i)
259
- Base. setindex! (A:: T24Linear{T} , v, i:: Int ) where {T} = setfield! (A, i, convert (T, v))
260
-
261
- # A custom linear slow sparse-like array that relies upon Dict for its storage
262
- struct TSlow{T,N} <: AbstractArray{T,N}
263
- data:: Dict{NTuple{N,Int}, T}
264
- dims:: NTuple{N,Int}
234
+ if ! isdefined (@__MODULE__ , :T24Linear )
235
+ include (" testhelpers/arrayindexingtypes.jl" )
265
236
end
266
- TSlow (:: Type{T} , dims:: Int... ) where {T} = TSlow (T, dims)
267
- TSlow (:: Type{T} , dims:: NTuple{N,Int} ) where {T,N} = TSlow {T,N} (Dict {NTuple{N,Int}, T} (), dims)
268
-
269
- TSlow {T,N} (X:: TSlow{T,N} ) where {T,N } = X
270
- TSlow ( X:: AbstractArray{T,N} ) where {T,N } = TSlow {T,N} (X)
271
- TSlow {T } (X:: AbstractArray{_,N} ) where {T,N,_} = TSlow {T,N} (X)
272
- TSlow {T,N} (X:: AbstractArray ) where {T,N } = begin
273
- A = TSlow (T, size (X))
274
- for I in CartesianIndices (size (X))
275
- A[I. I... ] = X[I. I... ]
276
- end
277
- A
278
- end
279
-
280
- Base. size (A:: TSlow ) = A. dims
281
- Base. similar (A:: TSlow , :: Type{T} , dims:: Dims ) where {T} = TSlow (T, dims)
282
- import Base: IndexCartesian
283
- Base. IndexStyle (:: Type{A} ) where {A<: TSlow } = IndexCartesian ()
284
- # Until #11242 is merged, we need to define each dimension independently
285
- Base. getindex (A:: TSlow{T,0} ) where {T} = get (A. data, (), zero (T))
286
- Base. getindex (A:: TSlow{T,1} , i1:: Int ) where {T} = get (A. data, (i1,), zero (T))
287
- Base. getindex (A:: TSlow{T,2} , i1:: Int , i2:: Int ) where {T} = get (A. data, (i1,i2), zero (T))
288
- Base. getindex (A:: TSlow{T,3} , i1:: Int , i2:: Int , i3:: Int ) where {T} =
289
- get (A. data, (i1,i2,i3), zero (T))
290
- Base. getindex (A:: TSlow{T,4} , i1:: Int , i2:: Int , i3:: Int , i4:: Int ) where {T} =
291
- get (A. data, (i1,i2,i3,i4), zero (T))
292
- Base. getindex (A:: TSlow{T,5} , i1:: Int , i2:: Int , i3:: Int , i4:: Int , i5:: Int ) where {T} =
293
- get (A. data, (i1,i2,i3,i4,i5), zero (T))
294
-
295
- Base. setindex! (A:: TSlow{T,0} , v) where {T} = (A. data[()] = v)
296
- Base. setindex! (A:: TSlow{T,1} , v, i1:: Int ) where {T} = (A. data[(i1,)] = v)
297
- Base. setindex! (A:: TSlow{T,2} , v, i1:: Int , i2:: Int ) where {T} = (A. data[(i1,i2)] = v)
298
- Base. setindex! (A:: TSlow{T,3} , v, i1:: Int , i2:: Int , i3:: Int ) where {T} =
299
- (A. data[(i1,i2,i3)] = v)
300
- Base. setindex! (A:: TSlow{T,4} , v, i1:: Int , i2:: Int , i3:: Int , i4:: Int ) where {T} =
301
- (A. data[(i1,i2,i3,i4)] = v)
302
- Base. setindex! (A:: TSlow{T,5} , v, i1:: Int , i2:: Int , i3:: Int , i4:: Int , i5:: Int ) where {T} =
303
- (A. data[(i1,i2,i3,i4,i5)] = v)
304
237
305
238
const can_inline = Base. JLOptions (). can_inline != 0
306
239
function test_scalar_indexing (:: Type{T} , shape, :: Type{TestAbstractArray} ) where T
0 commit comments