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