@@ -12,8 +12,12 @@ immutable SubArray{T,N,P,I,L} <: AbstractArray{T,N}
12
12
first_index:: Int # for linear indexing and pointer, only valid when L==true
13
13
stride1:: Int # used only for linear indexing
14
14
end
15
+ # Ensure the dimensionality of the parent matches the number of indices
16
+ function SubArray {N} (parent:: AbstractArray , indexes:: NTuple{N} , dims:: Tuple )
17
+ SubArray (reshape (parent, Val{N}), indexes, dims)
18
+ end
15
19
# Compute the linear indexability of the indices, and combine it with the linear indexing of the parent
16
- function SubArray (parent:: AbstractArray , indexes:: Tuple , dims:: Tuple )
20
+ function SubArray {T,N} (parent:: AbstractArray{T,N} , indexes:: NTuple{N} , dims:: Tuple )
17
21
SubArray (linearindexing (viewindexing (indexes), linearindexing (parent)), parent, indexes, convert (Dims, dims))
18
22
end
19
23
function SubArray {P, I, N} (:: LinearSlow , parent:: P , indexes:: I , dims:: NTuple{N, Int} )
@@ -77,14 +81,7 @@ parentindexes(a::AbstractArray) = ntuple(i->1:size(a,i), ndims(a))
77
81
78
82
# # SubArray creation
79
83
# 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... )
86
- end
87
- function _slice {T,N} (A:: AbstractArray{T,N} , I:: Vararg{ViewIndex,N} )
84
+ function slice (A:: AbstractArray , I:: ViewIndex... )
88
85
@_inline_meta
89
86
@boundscheck checkbounds (A, I... )
90
87
J = to_indexes (I... )
@@ -96,14 +93,7 @@ keep_leading_scalars(T::Tuple{Real, Vararg{Real}}) = T
96
93
keep_leading_scalars (T:: Tuple{Real, Vararg{Any}} ) = (@_inline_meta ; (NoSlice (T[1 ]), keep_leading_scalars (tail (T))... ))
97
94
keep_leading_scalars (T:: Tuple{Any, Vararg{Any}} ) = (@_inline_meta ; (T[1 ], keep_leading_scalars (tail (T))... ))
98
95
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... )
105
- end
106
- function _sub {T,N} (A:: AbstractArray{T,N} , I:: Vararg{ViewIndex,N} )
96
+ function sub (A:: AbstractArray , I:: Vararg... )
107
97
@_inline_meta
108
98
@boundscheck checkbounds (A, I... )
109
99
J = keep_leading_scalars (to_indexes (I... ))
0 commit comments