@@ -92,7 +92,7 @@ Base.axes1(A::OffsetArray{T,0}) where {T} = 1:1 # we only need to specialize th
9292# Avoid the kw-arg on the range(r+x, length=length(r)) call in r .+ x
9393@inline _slice (r, x) = IdentityUnitRange (Base. _range (first (r) + x, nothing , nothing , length (r)))
9494
95- const OffsetAxis = Union{Integer, UnitRange, Base. OneTo, IdentityUnitRange}
95+ const OffsetAxis = Union{Integer, UnitRange, Base. OneTo, IdentityUnitRange, Colon }
9696function Base. similar (A:: OffsetArray , :: Type{T} , dims:: Dims ) where T
9797 B = similar (parent (A), T, dims)
9898end
@@ -101,6 +101,7 @@ function Base.similar(A::AbstractArray, ::Type{T}, inds::Tuple{OffsetAxis,Vararg
101101 OffsetArray (B, map (indexoffset, inds))
102102end
103103
104+ Base. reshape (A:: AbstractArray , inds:: OffsetAxis... ) = reshape (A, inds)
104105Base. reshape (A:: AbstractArray , inds:: Tuple{OffsetAxis,Vararg{OffsetAxis}} ) =
105106 OffsetArray (reshape (A, map (indexlength, inds)), map (indexoffset, inds))
106107
@@ -111,6 +112,8 @@ Base.reshape(A::OffsetArray, inds::Tuple{OffsetAxis,Vararg{OffsetAxis}}) =
111112# And for non-offset axes, we can just return a reshape of the parent directly
112113Base. reshape (A:: OffsetArray , inds:: Tuple{Union{Integer,Base.OneTo},Vararg{Union{Integer,Base.OneTo}}} ) = reshape (parent (A), inds)
113114Base. reshape (A:: OffsetArray , inds:: Dims ) = reshape (parent (A), inds)
115+ Base. reshape (A:: OffsetArray , inds:: Union{Int,Colon} ...) = reshape (parent (A), inds)
116+ Base. reshape (A:: OffsetArray , inds:: Tuple{Vararg{Union{Int,Colon}}} ) = reshape (parent (A), inds)
114117
115118Base. similar (:: Type{T} , shape:: Tuple{OffsetAxis,Vararg{OffsetAxis}} ) where {T<: AbstractArray } =
116119 OffsetArray (T (undef, map (indexlength, shape)), map (indexoffset, shape))
@@ -217,8 +220,10 @@ offset(offsets::Tuple{Vararg{Int}}, inds::Tuple{}) = error("inds cannot be short
217220
218221indexoffset (r:: AbstractRange ) = first (r) - 1
219222indexoffset (i:: Integer ) = 0
223+ indexoffset (i:: Colon ) = 0
220224indexlength (r:: AbstractRange ) = length (r)
221225indexlength (i:: Integer ) = i
226+ indexlength (i:: Colon ) = Colon ()
222227
223228@eval @deprecate $ (Symbol (" @unsafe" )) $ (Symbol (" @inbounds" ))
224229
0 commit comments