@@ -92,7 +92,7 @@ Base.axes1(A::OffsetArray{T,0}) where {T} = 1:1 # we only need to specialize th
92
92
# Avoid the kw-arg on the range(r+x, length=length(r)) call in r .+ x
93
93
@inline _slice (r, x) = IdentityUnitRange (Base. _range (first (r) + x, nothing , nothing , length (r)))
94
94
95
- const OffsetAxis = Union{Integer, UnitRange, Base. OneTo, IdentityUnitRange}
95
+ const OffsetAxis = Union{Integer, UnitRange, Base. OneTo, IdentityUnitRange, Colon }
96
96
function Base. similar (A:: OffsetArray , :: Type{T} , dims:: Dims ) where T
97
97
B = similar (parent (A), T, dims)
98
98
end
@@ -101,6 +101,7 @@ function Base.similar(A::AbstractArray, ::Type{T}, inds::Tuple{OffsetAxis,Vararg
101
101
OffsetArray (B, map (indexoffset, inds))
102
102
end
103
103
104
+ Base. reshape (A:: AbstractArray , inds:: OffsetAxis... ) = reshape (A, inds)
104
105
Base. reshape (A:: AbstractArray , inds:: Tuple{OffsetAxis,Vararg{OffsetAxis}} ) =
105
106
OffsetArray (reshape (A, map (indexlength, inds)), map (indexoffset, inds))
106
107
@@ -111,6 +112,8 @@ Base.reshape(A::OffsetArray, inds::Tuple{OffsetAxis,Vararg{OffsetAxis}}) =
111
112
# And for non-offset axes, we can just return a reshape of the parent directly
112
113
Base. reshape (A:: OffsetArray , inds:: Tuple{Union{Integer,Base.OneTo},Vararg{Union{Integer,Base.OneTo}}} ) = reshape (parent (A), inds)
113
114
Base. 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)
114
117
115
118
Base. similar (:: Type{T} , shape:: Tuple{OffsetAxis,Vararg{OffsetAxis}} ) where {T<: AbstractArray } =
116
119
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
217
220
218
221
indexoffset (r:: AbstractRange ) = first (r) - 1
219
222
indexoffset (i:: Integer ) = 0
223
+ indexoffset (i:: Colon ) = 0
220
224
indexlength (r:: AbstractRange ) = length (r)
221
225
indexlength (i:: Integer ) = i
226
+ indexlength (i:: Colon ) = Colon ()
222
227
223
228
@eval @deprecate $ (Symbol (" @unsafe" )) $ (Symbol (" @inbounds" ))
224
229
0 commit comments