@@ -435,13 +435,9 @@ getindex(t::Tuple, i::CartesianIndex{1}) = getindex(t, i.I[1])
435
435
# These are not defined on directly on getindex to avoid
436
436
# ambiguities for AbstractArray subtypes. See the note in abstractarray.jl
437
437
438
- @generated function _getindex (l:: IndexStyle , A:: AbstractArray , I:: Union{Real, AbstractArray} ...)
439
- N = length (I)
440
- quote
441
- @_inline_meta
442
- @boundscheck checkbounds (A, I... )
443
- _unsafe_getindex (l, _maybe_reshape (l, A, I... ), I... )
444
- end
438
+ @inline function _getindex (l:: IndexStyle , A:: AbstractArray , I:: Union{Real, AbstractArray} ...)
439
+ @boundscheck checkbounds (A, I... )
440
+ return _unsafe_getindex (l, _maybe_reshape (l, A, I... ), I... )
445
441
end
446
442
# But we can speed up IndexCartesian arrays by reshaping them to the appropriate dimensionality:
447
443
_maybe_reshape (:: IndexLinear , A:: AbstractArray , I... ) = A
@@ -450,31 +446,26 @@ _maybe_reshape(::IndexCartesian, A::AbstractVector, I...) = A
450
446
@inline __maybe_reshape (A:: AbstractArray{T,N} , :: NTuple{N,Any} ) where {T,N} = A
451
447
@inline __maybe_reshape (A:: AbstractArray , :: NTuple{N,Any} ) where {N} = reshape (A, Val{N})
452
448
453
- @generated function _unsafe_getindex (:: IndexStyle , A:: AbstractArray , I:: Union{Real, AbstractArray} ...)
454
- N = length (I)
455
- quote
456
- # This is specifically not inlined to prevent exessive allocations in type unstable code
457
- @nexprs $ N d-> (I_d = I[d])
458
- shape = @ncall $ N index_shape I
459
- dest = similar (A, shape)
460
- map (unsafe_length, indices (dest)) == map (unsafe_length, shape) || throw_checksize_error (dest, shape)
461
- @ncall $ N _unsafe_getindex! dest A I
462
- end
449
+ function _unsafe_getindex (:: IndexStyle , A:: AbstractArray , I:: Vararg{Union{Real, AbstractArray}, N} ) where N
450
+ # This is specifically not inlined to prevent excessive allocations in type unstable code
451
+ shape = index_shape (I... )
452
+ dest = similar (A, shape)
453
+ map (unsafe_length, indices (dest)) == map (unsafe_length, shape) || throw_checksize_error (dest, shape)
454
+ _unsafe_getindex! (dest, A, I... ) # usually a generated function, don't allow it to impact inference result
455
+ return dest
463
456
end
464
457
465
458
# Always index with the exactly indices provided.
466
- @generated function _unsafe_getindex! (dest:: AbstractArray , src:: AbstractArray , I:: Union{Real, AbstractArray} ...)
467
- N = length (I)
459
+ @generated function _unsafe_getindex! (dest:: AbstractArray , src:: AbstractArray , I:: Vararg{Union{Real, AbstractArray}, N} ) where N
468
460
quote
469
- $ (Expr (:meta , :inline ))
470
- @nexprs $ N d-> (J_d = I[d])
461
+ @_inline_meta
471
462
D = eachindex (dest)
472
463
Ds = start (D)
473
- @inbounds @nloops $ N j d-> J_d begin
464
+ @inbounds @nloops $ N j d-> I[d] begin
474
465
d, Ds = next (D, Ds)
475
466
dest[d] = @ncall $ N getindex src j
476
467
end
477
- dest
468
+ return dest
478
469
end
479
470
end
480
471
0 commit comments