Skip to content

Commit 40ad6be

Browse files
committed
Revert "Simpler reshaping for SubArray"
This reverts commit fa97a6eba524955fffe9b54649a57031815a88e5.
1 parent c0d1675 commit 40ad6be

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

base/subarray.jl

+17-7
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ immutable SubArray{T,N,P,I,L} <: AbstractArray{T,N}
1212
first_index::Int # for linear indexing and pointer, only valid when L==true
1313
stride1::Int # used only for linear indexing
1414
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
1915
# 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)
2117
SubArray(linearindexing(viewindexing(indexes), linearindexing(parent)), parent, indexes, convert(Dims, dims))
2218
end
2319
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))
8177

8278
## SubArray creation
8379
# 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})
8588
@_inline_meta
8689
@boundscheck checkbounds(A, I...)
8790
J = to_indexes(I...)
@@ -93,7 +96,14 @@ keep_leading_scalars(T::Tuple{Real, Vararg{Real}}) = T
9396
keep_leading_scalars(T::Tuple{Real, Vararg{Any}}) = (@_inline_meta; (NoSlice(T[1]), keep_leading_scalars(tail(T))...))
9497
keep_leading_scalars(T::Tuple{Any, Vararg{Any}}) = (@_inline_meta; (T[1], keep_leading_scalars(tail(T))...))
9598

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})
97107
@_inline_meta
98108
@boundscheck checkbounds(A, I...)
99109
J = keep_leading_scalars(to_indexes(I...))

0 commit comments

Comments
 (0)