@@ -91,50 +91,46 @@ Base._maybe_reindex(V::SSubArray, I, A::Tuple{AbstractArray{<:Base.AbstractCarte
9191Base. _maybe_reindex (V:: SSubArray , I, A:: Tuple{Any, Vararg{Any}} ) = (Base. @_inline_meta ; Base. _maybe_reindex (V, I, Base. tail (A)))
9292function Base. _maybe_reindex (V:: SSubArray , I, :: Tuple{} )
9393 Base. @_inline_meta
94- @inbounds idxs = to_indices (V. parent, reindex (V. indices, I))
94+ @inbounds idxs = to_indices (V. parent, _reindex (V. indices, I))
9595 return Base. unsafe_view (V. parent, idxs... )
9696end
9797
98- if VERSION < v " 1.2"
99- # reindex copied from Base because in pre-1.2 it has an incompatible implementation
100- reindex (:: Tuple{} , :: Tuple{} ) = ()
101-
102- # Skip dropped scalars, so simply peel them off the parent indices and continue
103- reindex (idxs:: Tuple{Base.ScalarIndex, Vararg{Any}} , subidxs:: Tuple{Vararg{Any}} ) =
104- (Base. @_propagate_inbounds_meta ; (idxs[1 ], reindex (Base. tail (idxs), subidxs)... ))
105-
106- # Slices simply pass their subindices straight through
107- reindex (idxs:: Tuple{Base.Slice, Vararg{Any}} , subidxs:: Tuple{Any, Vararg{Any}} ) =
108- (Base. @_propagate_inbounds_meta ; (subidxs[1 ], reindex (Base. tail (idxs), Base. tail (subidxs))... ))
109-
110- # Re-index into parent vectors with one subindex
111- reindex (idxs:: Tuple{AbstractVector, Vararg{Any}} , subidxs:: Tuple{Any, Vararg{Any}} ) =
112- (Base. @_propagate_inbounds_meta ; (idxs[1 ][subidxs[1 ]], reindex (Base. tail (idxs), Base. tail (subidxs))... ))
113-
114- # Parent matrices are re-indexed with two sub-indices
115- reindex (idxs:: Tuple{AbstractMatrix, Vararg{Any}} , subidxs:: Tuple{Any, Any, Vararg{Any}} ) =
116- (Base. @_propagate_inbounds_meta ; (idxs[1 ][subidxs[1 ], subidxs[2 ]], reindex (Base. tail (idxs), Base. tail (Base. tail (subidxs)))... ))
117-
118- # In general, we index N-dimensional parent arrays with N indices
119- @generated function reindex (idxs:: Tuple{AbstractArray{T,N}, Vararg{Any}} , subidxs:: Tuple{Vararg{Any}} ) where {T,N}
120- if length (subidxs. parameters) >= N
121- subs = [:(subidxs[$ d]) for d in 1 : N]
122- tail = [:(subidxs[$ d]) for d in N+ 1 : length (subidxs. parameters)]
123- :(Base. @_propagate_inbounds_meta ; (idxs[1 ][$ (subs... )], reindex (Base. tail (idxs), ($ (tail... ),))... ))
124- else
125- :(throw (ArgumentError (" cannot re-index SubArray with fewer indices than dimensions\n This should not occur; please submit a bug report." )))
126- end
98+ # reindex was copied from Base because in pre-1.2 it has an incompatible implementation
99+ _reindex (:: Tuple{} , :: Tuple{} ) = ()
100+
101+ # Skip dropped scalars, so simply peel them off the parent indices and continue
102+ _reindex (idxs:: Tuple{Base.ScalarIndex, Vararg{Any}} , subidxs:: Tuple{Vararg{Any}} ) =
103+ (Base. @_propagate_inbounds_meta ; (idxs[1 ], _reindex (Base. tail (idxs), subidxs)... ))
104+
105+ # Slices simply pass their subindices straight through
106+ _reindex (idxs:: Tuple{Base.Slice, Vararg{Any}} , subidxs:: Tuple{Any, Vararg{Any}} ) =
107+ (Base. @_propagate_inbounds_meta ; (subidxs[1 ], _reindex (Base. tail (idxs), Base. tail (subidxs))... ))
108+
109+ # Re-index into parent vectors with one subindex
110+ _reindex (idxs:: Tuple{AbstractVector, Vararg{Any}} , subidxs:: Tuple{Any, Vararg{Any}} ) =
111+ (Base. @_propagate_inbounds_meta ; (idxs[1 ][subidxs[1 ]], _reindex (Base. tail (idxs), Base. tail (subidxs))... ))
112+
113+ # Parent matrices are re-indexed with two sub-indices
114+ _reindex (idxs:: Tuple{AbstractMatrix, Vararg{Any}} , subidxs:: Tuple{Any, Any, Vararg{Any}} ) =
115+ (Base. @_propagate_inbounds_meta ; (idxs[1 ][subidxs[1 ], subidxs[2 ]], _reindex (Base. tail (idxs), Base. tail (Base. tail (subidxs)))... ))
116+
117+ # In general, we index N-dimensional parent arrays with N indices
118+ @generated function _reindex (idxs:: Tuple{AbstractArray{T,N}, Vararg{Any}} , subidxs:: Tuple{Vararg{Any}} ) where {T,N}
119+ if length (subidxs. parameters) >= N
120+ subs = [:(subidxs[$ d]) for d in 1 : N]
121+ tail = [:(subidxs[$ d]) for d in N+ 1 : length (subidxs. parameters)]
122+ :(Base. @_propagate_inbounds_meta ; (idxs[1 ][$ (subs... )], _reindex (Base. tail (idxs), ($ (tail... ),))... ))
123+ else
124+ :(throw (ArgumentError (" cannot re-index SubArray with fewer indices than dimensions\n This should not occur; please submit a bug report." )))
127125 end
128- else
129- using Base: reindex
130126end
131127
132128# In general, we simply re-index the parent indices by the provided ones
133129SlowSSubArray{S,T,N,P,I} = SSubArray{S,T,N,P,I,false }
134130function getindex (V:: SSubArray{S,T,N} , I:: Vararg{Int,N} ) where {S,T,N}
135131 Base. @_inline_meta
136132 @boundscheck checkbounds (V, I... )
137- @inbounds r = V. parent[reindex (V. indices, I)... ]
133+ @inbounds r = V. parent[_reindex (V. indices, I)... ]
138134 r
139135end
140136
@@ -143,7 +139,7 @@ function getindex(V::SSubArray, i::Int)
143139 Base. @_inline_meta
144140 @boundscheck checkbounds (V, i)
145141 subind = Base. _to_subscript_indices (V, i)
146- @inbounds r = V. parent[reindex (V. indices, subind)... ]
142+ @inbounds r = V. parent[_reindex (V. indices, subind)... ]
147143 return r
148144end
149145
@@ -193,14 +189,14 @@ end
193189function setindex! (V:: SSubArray{T,N} , x, I:: Vararg{Int,N} ) where {T,N}
194190 Base. @_inline_meta
195191 @boundscheck checkbounds (V, I... )
196- @inbounds V. parent[reindex (V. indices, I)... ] = x
192+ @inbounds V. parent[_reindex (V. indices, I)... ] = x
197193 V
198194end
199195# overrides the default setindex! from `StaticArrays`
200196function setindex! (V:: SSubArray , x, i:: Int )
201197 Base. @_inline_meta
202198 subind = Base. _to_subscript_indices (V, i)
203- @inbounds V. parent[reindex (V. indices, subind)... ] = x
199+ @inbounds V. parent[_reindex (V. indices, subind)... ] = x
204200 V
205201end
206202function setindex! (V:: FastSSubArray , x, i:: Int )
0 commit comments