@@ -187,14 +187,14 @@ index_shape_dim(A, dim, ::Colon) = (trailingsize(A, dim),)
187
187
checkbounds (A, I... )
188
188
_unsafe_getindex (l, A, I... )
189
189
end
190
- @generated function _unsafe_getindex (l :: LinearIndexing , A:: AbstractArray , I:: Union{Real, AbstractArray, Colon} ...)
190
+ @generated function _unsafe_getindex (:: LinearIndexing , A:: AbstractArray , I:: Union{Real, AbstractArray, Colon} ...)
191
191
N = length (I)
192
192
quote
193
193
# This is specifically *not* inlined.
194
194
@nexprs $ N d-> (I_d = to_index (I[d]))
195
195
dest = similar (A, @ncall $ N index_shape A I)
196
196
@ncall $ N checksize dest I
197
- @ncall $ N _unsafe_getindex! dest l A I
197
+ @ncall $ N _unsafe_getindex! dest A I
198
198
end
199
199
end
200
200
221
221
222
222
# Indexing with an array of indices is inherently linear in the source, but
223
223
# might be able to be optimized with fast dividing integers
224
- @inline function _unsafe_getindex! (dest:: AbstractArray , :: LinearIndexing , src:: AbstractArray , I:: AbstractArray )
224
+ @inline function _unsafe_getindex! (dest:: AbstractArray , src:: AbstractArray , I:: AbstractArray )
225
225
D = eachindex (dest)
226
226
Ds = start (D)
227
227
for idx in I
231
231
dest
232
232
end
233
233
234
- # Fast source - compute the linear index
235
- @generated function _unsafe_getindex! (dest:: AbstractArray , :: LinearFast , src:: AbstractArray , I:: Union{Real, AbstractVector, Colon} ...)
236
- N = length (I)
237
- quote
238
- $ (Expr (:meta , :inline ))
239
- stride_1 = 1
240
- @nexprs $ N d-> (stride_{d+ 1 } = stride_d* size (src, d))
241
- $ (symbol (:offset_ , N)) = 1
242
- D = eachindex (dest)
243
- Ds = start (D)
244
- @nloops $ N i dest d-> (offset_{d- 1 } = offset_d + (unsafe_getindex (I[d], i_d)- 1 )* stride_d) begin
245
- d, Ds = next (D, Ds)
246
- unsafe_setindex! (dest, unsafe_getindex (src, offset_0), d)
247
- end
248
- dest
249
- end
250
- end
251
- # Slow source - index with the indices provided.
252
- # TODO : this may not be the full dimensionality; that case could be optimized
253
- @generated function _unsafe_getindex! (dest:: AbstractArray , :: LinearSlow , src:: AbstractArray , I:: Union{Real, AbstractVector, Colon} ...)
234
+ # Always index with the exactly indices provided.
235
+ @generated function _unsafe_getindex! (dest:: AbstractArray , src:: AbstractArray , I:: Union{Real, AbstractVector, Colon} ...)
254
236
N = length (I)
255
237
quote
256
238
$ (Expr (:meta , :inline ))
@@ -292,8 +274,8 @@ _iterable(v) = repeated(v)
292
274
checkbounds (A, J... )
293
275
_unsafe_setindex! (l, A, x, J... )
294
276
end
295
- @inline function _unsafe_setindex! (l :: LinearIndexing , A:: AbstractArray , x, J:: Union{Real,AbstractArray,Colon} ...)
296
- _unsafe_batchsetindex! (l, A, _iterable (x), to_indexes (J... )... )
277
+ @inline function _unsafe_setindex! (:: LinearIndexing , A:: AbstractArray , x, J:: Union{Real,AbstractArray,Colon} ...)
278
+ _unsafe_batchsetindex! (A, _iterable (x), to_indexes (J... )... )
297
279
end
298
280
299
281
# 1-d logical indexing: override the above to avoid calling find (in to_index)
@@ -315,25 +297,7 @@ function _unsafe_setindex!(::LinearIndexing, A::AbstractArray, x, I::AbstractArr
315
297
A
316
298
end
317
299
318
- # Use iteration over X so we don't need to worry about its storage
319
- @generated function _unsafe_batchsetindex! (:: LinearFast , A:: AbstractArray , X, I:: Union{Real,AbstractArray,Colon} ...)
320
- N = length (I)
321
- quote
322
- @nexprs $ N d-> (I_d = I[d])
323
- idxlens = @ncall $ N index_lengths A I
324
- @ncall $ N setindex_shape_check X (d-> idxlens[d])
325
- Xs = start (X)
326
- stride_1 = 1
327
- @nexprs $ N d-> (stride_{d+ 1 } = stride_d* size (A,d))
328
- $ (symbol (:offset_ , N)) = 1
329
- @nloops $ N i d-> (1 : idxlens[d]) d-> (offset_{d- 1 } = offset_d + (unsafe_getindex (I_d, i_d)- 1 )* stride_d) begin
330
- v, Xs = next (X, Xs)
331
- unsafe_setindex! (A, v, offset_0)
332
- end
333
- A
334
- end
335
- end
336
- @generated function _unsafe_batchsetindex! (:: LinearSlow , A:: AbstractArray , X, I:: Union{Real,AbstractArray,Colon} ...)
300
+ @generated function _unsafe_batchsetindex! (A:: AbstractArray , X, I:: Union{Real,AbstractArray,Colon} ...)
337
301
N = length (I)
338
302
quote
339
303
@nexprs $ N d-> (I_d = I[d])
0 commit comments