@@ -77,16 +77,23 @@ parentindexes(a::AbstractArray) = ntuple(i->1:size(a,i), ndims(a))
77
77
78
78
# # SubArray creation
79
79
# Drops singleton dimensions (those indexed with a scalar)
80
- slice {T,N} (A:: AbstractArray{T,N} , I:: Vararg{ViewIndex,N} ) = (@_propagate_inbounds_meta ; _slice (A, I... ))
81
- slice (A:: AbstractVector , i:: ViewIndex ) = (@_propagate_inbounds_meta ; _slice (A, i))
82
- slice (A:: AbstractArray , i:: ViewIndex ) = (@_propagate_inbounds_meta ; _slice (reshape (A, length (A)), i))
83
- function slice {N} (A:: AbstractArray , I:: Vararg{ViewIndex,N} ) # TODO : DEPRECATE FOR #14770
84
- @_propagate_inbounds_meta
85
- _slice (reshape (A, Val{N}), I... )
80
+ function slice {T,N} (A:: AbstractArray{T,N} , I:: Vararg{ViewIndex,N} )
81
+ @_inline_meta
82
+ @boundscheck checkbounds (A, I... )
83
+ unsafe_slice (A, I... )
86
84
end
87
- function _slice {T,N} (A:: AbstractArray{T,N} , I:: Vararg{ViewIndex,N} )
85
+ function slice (A:: AbstractArray , i:: ViewIndex )
86
+ @_inline_meta
87
+ @boundscheck checkbounds (A, i)
88
+ unsafe_slice (reshape (A, Val{1 }), i)
89
+ end
90
+ function slice {N} (A:: AbstractArray , I:: Vararg{ViewIndex,N} ) # TODO : DEPRECATE FOR #14770
88
91
@_inline_meta
89
92
@boundscheck checkbounds (A, I... )
93
+ unsafe_slice (reshape (A, Val{N}), I... )
94
+ end
95
+ function unsafe_slice {T,N} (A:: AbstractArray{T,N} , I:: Vararg{ViewIndex,N} )
96
+ @_inline_meta
90
97
J = to_indexes (I... )
91
98
SubArray (A, J, index_shape (A, J... ))
92
99
end
@@ -96,16 +103,23 @@ keep_leading_scalars(T::Tuple{Real, Vararg{Real}}) = T
96
103
keep_leading_scalars (T:: Tuple{Real, Vararg{Any}} ) = (@_inline_meta ; (NoSlice (T[1 ]), keep_leading_scalars (tail (T))... ))
97
104
keep_leading_scalars (T:: Tuple{Any, Vararg{Any}} ) = (@_inline_meta ; (T[1 ], keep_leading_scalars (tail (T))... ))
98
105
99
- sub {T,N} (A:: AbstractArray{T,N} , I:: Vararg{ViewIndex,N} ) = (@_propagate_inbounds_meta ; _sub (A, I... ))
100
- sub (A:: AbstractVector , i:: ViewIndex ) = (@_propagate_inbounds_meta ; _sub (A, i))
101
- sub (A:: AbstractArray , i:: ViewIndex ) = (@_propagate_inbounds_meta ; _sub (reshape (A, length (A)), i))
102
- function sub {N} (A:: AbstractArray , I:: Vararg{ViewIndex,N} ) # TODO : DEPRECATE FOR #14770
103
- @_propagate_inbounds_meta
104
- _sub (reshape (A, Val{N}), I... )
106
+ function sub {T,N} (A:: AbstractArray{T,N} , I:: Vararg{ViewIndex,N} )
107
+ @_inline_meta
108
+ @boundscheck checkbounds (A, I... )
109
+ unsafe_sub (A, I... )
105
110
end
106
- function _sub {T,N} (A:: AbstractArray{T,N} , I:: Vararg{ViewIndex,N} )
111
+ function sub (A:: AbstractArray , i:: ViewIndex )
112
+ @_inline_meta
113
+ @boundscheck checkbounds (A, i)
114
+ unsafe_sub (reshape (A, Val{1 }), i)
115
+ end
116
+ function sub {N} (A:: AbstractArray , I:: Vararg{ViewIndex,N} ) # TODO : DEPRECATE FOR #14770
107
117
@_inline_meta
108
118
@boundscheck checkbounds (A, I... )
119
+ unsafe_sub (reshape (A, Val{N}), I... )
120
+ end
121
+ function unsafe_sub {T,N} (A:: AbstractArray{T,N} , I:: Vararg{ViewIndex,N} )
122
+ @_inline_meta
109
123
J = keep_leading_scalars (to_indexes (I... ))
110
124
SubArray (A, J, index_shape (A, J... ))
111
125
end
@@ -218,22 +232,14 @@ function setindex!(V::FastContiguousSubArray, x, i::Real)
218
232
end
219
233
# Nonscalar setindex! falls back to the defaults
220
234
221
- slice {T,N} (V:: SubArray{T,N} , I:: Vararg{ViewIndex,N} ) = _slice (V, I... )
222
- slice {T} (V:: SubArray{T,1} , i:: ViewIndex ) = _slice (V, i)
223
- slice (V:: SubArray , i:: ViewIndex ) = _slice (reshape (V, length (V)), i)
224
- function _slice {T,N} (V:: SubArray{T,N} , I:: Vararg{ViewIndex,N} )
235
+ function unsafe_slice {T,N} (V:: SubArray{T,N} , I:: Vararg{ViewIndex,N} )
225
236
@_inline_meta
226
- @boundscheck checkbounds (V, I... )
227
237
idxs = reindex (V, V. indexes, to_indexes (I... ))
228
238
SubArray (V. parent, idxs, index_shape (V. parent, idxs... ))
229
239
end
230
240
231
- sub {T,N} (V:: SubArray{T,N} , I:: Vararg{ViewIndex,N} ) = _sub (V, I... )
232
- sub {T} (V:: SubArray{T,1} , i:: ViewIndex ) = _sub (V, i)
233
- sub (V:: SubArray , i:: ViewIndex ) = _sub (reshape (V, length (V)), i)
234
- function _sub {T,N} (V:: SubArray{T,N} , I:: Vararg{ViewIndex,N} )
241
+ function unsafe_sub {T,N} (V:: SubArray{T,N} , I:: Vararg{ViewIndex,N} )
235
242
@_inline_meta
236
- @boundscheck checkbounds (V, I... )
237
243
idxs = reindex (V, V. indexes, keep_leading_scalars (to_indexes (I... )))
238
244
SubArray (V. parent, idxs, index_shape (V. parent, idxs... ))
239
245
end
0 commit comments