@@ -96,6 +96,7 @@ reshape(parent::AbstractArray, shp::Tuple{Union{Integer,OneTo}, Vararg{Union{Int
9696reshape (parent:: AbstractArray , dims:: Dims ) = _reshape (parent, dims)
9797
9898# Allow missing dimensions with Colon():
99+ reshape (parent:: AbstractVector , :: Colon ) = parent
99100reshape (parent:: AbstractArray , dims:: Int... ) = reshape (parent, dims)
100101reshape (parent:: AbstractArray , dims:: Union{Int,Colon} ...) = reshape (parent, dims)
101102reshape (parent:: AbstractArray , dims:: Tuple{Vararg{Union{Int,Colon}}} ) = _reshape (parent, _reshape_uncolon (parent, dims))
@@ -201,6 +202,8 @@ dataids(A::ReshapedArray) = dataids(A.parent)
201202 d, r = divrem (ind, strds[1 ])
202203 (_ind2sub_rs (front (ax), tail (strds), r)... , d + first (ax[end ]))
203204end
205+ offset_if_vec (i:: Integer , axs:: Tuple{<:AbstractUnitRange} ) = i + first (axs[1 ]) - 1
206+ offset_if_vec (i:: Integer , axs:: Tuple ) = i
204207
205208@inline function getindex (A:: ReshapedArrayLF , index:: Int )
206209 @boundscheck checkbounds (A, index)
218221end
219222
220223@inline function _unsafe_getindex (A:: ReshapedArray{T,N} , indices:: Vararg{Int,N} ) where {T,N}
221- i = Base. _sub2ind (size (A), indices... )
222- I = ind2sub_rs (axes (A. parent), A. mi, i)
224+ axp = axes (A. parent)
225+ i = offset_if_vec (Base. _sub2ind (size (A), indices... ), axp)
226+ I = ind2sub_rs (axp, A. mi, i)
223227 _unsafe_getindex_rs (parent (A), I)
224228end
225229@inline _unsafe_getindex_rs (A, i:: Integer ) = (@inbounds ret = A[i]; ret)
241245end
242246
243247@inline function _unsafe_setindex! (A:: ReshapedArray{T,N} , val, indices:: Vararg{Int,N} ) where {T,N}
244- @inbounds parent (A)[ind2sub_rs (axes (A. parent), A. mi, Base. _sub2ind (size (A), indices... ))... ] = val
248+ axp = axes (A. parent)
249+ i = offset_if_vec (Base. _sub2ind (size (A), indices... ), axp)
250+ @inbounds parent (A)[ind2sub_rs (axes (A. parent), A. mi, i)... ] = val
245251 val
246252end
247253
0 commit comments