@@ -112,6 +112,7 @@ reshape(parent::AbstractArray, shp::Tuple{Union{Integer,OneTo}, Vararg{Union{Int
112
112
reshape (parent:: AbstractArray , dims:: Dims ) = _reshape (parent, dims)
113
113
114
114
# Allow missing dimensions with Colon():
115
+ reshape (parent:: AbstractVector , :: Colon ) = parent
115
116
reshape (parent:: AbstractArray , dims:: Int... ) = reshape (parent, dims)
116
117
reshape (parent:: AbstractArray , dims:: Union{Int,Colon} ...) = reshape (parent, dims)
117
118
reshape (parent:: AbstractArray , dims:: Tuple{Vararg{Union{Int,Colon}}} ) = _reshape (parent, _reshape_uncolon (parent, dims))
@@ -220,6 +221,8 @@ dataids(A::ReshapedArray) = dataids(A.parent)
220
221
d, r = divrem (ind, strds[1 ])
221
222
(_ind2sub_rs (front (ax), tail (strds), r)... , d + first (ax[end ]))
222
223
end
224
+ offset_if_vec (i:: Integer , axs:: Tuple{<:AbstractUnitRange} ) = i + first (axs[1 ]) - 1
225
+ offset_if_vec (i:: Integer , axs:: Tuple ) = i
223
226
224
227
@inline function getindex (A:: ReshapedArrayLF , index:: Int )
225
228
@boundscheck checkbounds (A, index)
237
240
end
238
241
239
242
@inline function _unsafe_getindex (A:: ReshapedArray{T,N} , indices:: Vararg{Int,N} ) where {T,N}
240
- i = Base. _sub2ind (size (A), indices... )
241
- I = ind2sub_rs (axes (A. parent), A. mi, i)
243
+ axp = axes (A. parent)
244
+ i = offset_if_vec (Base. _sub2ind (size (A), indices... ), axp)
245
+ I = ind2sub_rs (axp, A. mi, i)
242
246
_unsafe_getindex_rs (parent (A), I)
243
247
end
244
248
@inline _unsafe_getindex_rs (A, i:: Integer ) = (@inbounds ret = A[i]; ret)
260
264
end
261
265
262
266
@inline function _unsafe_setindex! (A:: ReshapedArray{T,N} , val, indices:: Vararg{Int,N} ) where {T,N}
263
- @inbounds parent (A)[ind2sub_rs (axes (A. parent), A. mi, Base. _sub2ind (size (A), indices... ))... ] = val
267
+ axp = axes (A. parent)
268
+ i = offset_if_vec (Base. _sub2ind (size (A), indices... ), axp)
269
+ @inbounds parent (A)[ind2sub_rs (axes (A. parent), A. mi, i)... ] = val
264
270
val
265
271
end
266
272
0 commit comments