@@ -320,12 +320,23 @@ Base.falses(inds::NTuple{N, Union{Integer, AbstractUnitRange}}) where {N} =
320320# and one obtains the result below.
321321parentindex (r:: IdOffsetRange , i) = i - r. offset
322322
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
324326 @boundscheck checkbounds (A, I... )
325327 J = map (parentindex, axes (A), I)
326328 @inbounds parent (A)[J... ]
327329end
328330
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+
329340@inline function Base. getindex (A:: OffsetVector , i:: Int )
330341 @boundscheck checkbounds (A, i)
331342 @inbounds parent (A)[parentindex (Base. axes1 (A), i)]
350361end
351362
352363Base. in (x, A:: OffsetArray ) = in (x, parent (A))
364+ Base. copy (A:: OffsetArray ) = OffsetArray (copy (A. parent), A. offsets)
353365
354366Base. strides (A:: OffsetArray ) = strides (parent (A))
355367Base. elsize (:: Type{OffsetArray{T,N,A}} ) where {T,N,A} = Base. elsize (A)
@@ -394,9 +406,6 @@ for OR in [:IIUR, :IdOffsetRange]
394406 end
395407end
396408
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-
400409# mapreduce is faster with an IdOffsetRange than with an OffsetUnitRange
401410# We therefore convert OffsetUnitRanges to IdOffsetRanges with the same values and axes
402411function Base. mapreduce (f, op, As:: OffsetUnitRange{<:Integer} ...; kw... )
0 commit comments