Skip to content

Commit 7d5b19a

Browse files
committed
Use Base.unsafe_view in getindex for ArrayOfSimilarArrays
Also remove specialized getindex for VectorOfSimilarArrays.
1 parent 6fbd9f7 commit 7d5b19a

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/array_of_similar_arrays.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@ Base.parent(A::ArrayOfSimilarArrays) = A.data
102102
Base.size(A::ArrayOfSimilarArrays{T,M,N}) where {T,M,N} = split_tuple(size(A.data), Val{M}())[2]
103103

104104

105-
Base.@propagate_inbounds Base.getindex(A::ArrayOfSimilarArrays{T,M,N}, idxs::Vararg{Integer,N}) where {T,M,N} =
106-
view(A.data, _ncolons(Val{M}())..., idxs...)
107-
105+
Base.@propagate_inbounds function Base.getindex(A::ArrayOfSimilarArrays{T,M,N}, idxs::Vararg{Integer,N}) where {T,M,N}
106+
@boundscheck checkbounds(A, idxs...)
107+
J = Base.to_indices(A.data, (_ncolons(Val{M}())..., idxs...))
108+
@boundscheck checkbounds(A.data, J...)
109+
Base.unsafe_view(A.data, J...)
110+
end
108111

109112
Base.@propagate_inbounds Base.setindex!(A::ArrayOfSimilarArrays{T,M,N}, x::AbstractArray{U,M}, idxs::Vararg{Integer,N}) where {T,M,N,U} =
110113
setindex!(A.data, x, _ncolons(Val{M}())..., idxs...)
@@ -174,10 +177,6 @@ VectorOfSimilarArrays(parent::AbstractArray{T,L}) where {T,L} =
174177
@inline Base.IndexStyle(V::VectorOfSimilarArrays) = IndexLinear()
175178

176179

177-
Base.@propagate_inbounds Base.getindex(A::VectorOfSimilarArrays{T,M}, rng::Union{Colon,UnitRange{<:Integer}}) where {T,M} =
178-
VectorOfSimilarArrays(view(A.data, _ncolons(Val{M}())..., rng))
179-
180-
181180
function Base.push!(V::VectorOfSimilarArrays{T,M}, x::AbstractArray{U,M}) where {T,M,U}
182181
size(x) != Base.front(size(V.data)) && throw(DimensionMismatch("Can't push, shape of source and elements of target is incompatible"))
183182
append!(V.data, x)

0 commit comments

Comments
 (0)