@@ -320,12 +320,23 @@ Base.falses(inds::NTuple{N, Union{Integer, AbstractUnitRange}}) where {N} =
320
320
# and one obtains the result below.
321
321
parentindex (r:: IdOffsetRange , i) = i - r. offset
322
322
323
- @inline function Base. getindex (A:: OffsetArray{T,N} , I:: Vararg{Int,N} ) where {T,N}
323
+ @propagate_inbounds Base. getindex (A:: OffsetArray{<:Any,0} ) = A. parent[]
324
+
325
+ @inline function Base. getindex (A:: OffsetArray{<:Any,N} , I:: Vararg{Int,N} ) where N
324
326
@boundscheck checkbounds (A, I... )
325
327
J = map (parentindex, axes (A), I)
326
328
@inbounds parent (A)[J... ]
327
329
end
328
330
331
+ @propagate_inbounds Base. getindex (A:: OffsetArray{<:Any,N} , c:: Vararg{Colon,N} ) where N =
332
+ OffsetArray (A. parent[c... ], A. offsets)
333
+
334
+ # With one Colon we use linear indexing.
335
+ # In this case we may forward the index to the parent, as the information about the axes is lost
336
+ # The exception to this is with OffsetVectors where the axis information is preserved,
337
+ # but that case is handled by getindex(::OffsetArray{<:Any,N}, ::Vararg{Colon,N})
338
+ @propagate_inbounds Base. getindex (A:: OffsetArray , c:: Colon ) = A. parent[:]
339
+
329
340
@inline function Base. getindex (A:: OffsetVector , i:: Int )
330
341
@boundscheck checkbounds (A, i)
331
342
@inbounds parent (A)[parentindex (Base. axes1 (A), i)]
350
361
end
351
362
352
363
Base. in (x, A:: OffsetArray ) = in (x, parent (A))
364
+ Base. copy (A:: OffsetArray ) = OffsetArray (copy (A. parent), A. offsets)
353
365
354
366
Base. strides (A:: OffsetArray ) = strides (parent (A))
355
367
Base. elsize (:: Type{OffsetArray{T,N,A}} ) where {T,N,A} = Base. elsize (A)
@@ -394,9 +406,6 @@ for OR in [:IIUR, :IdOffsetRange]
394
406
end
395
407
end
396
408
397
- # This is technically breaking, so it might be incorporated in the next major release
398
- # Base.getindex(a::OffsetRange, ::Colon) = OffsetArray(a.parent[:], a.offsets)
399
-
400
409
# mapreduce is faster with an IdOffsetRange than with an OffsetUnitRange
401
410
# We therefore convert OffsetUnitRanges to IdOffsetRanges with the same values and axes
402
411
function Base. mapreduce (f, op, As:: OffsetUnitRange{<:Integer} ...; kw... )
0 commit comments