Skip to content

Commit 6399ca5

Browse files
committed
Improve getindex implementation for VectorOfSimilarArrays
1 parent 7870e31 commit 6399ca5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/array_of_similar_arrays.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ Base.parent(A::ArrayOfSimilarArrays) = A.data
104104
Base.size(A::ArrayOfSimilarArrays{T,M,N}) where {T,M,N} = split_tuple(size(A.data), Val{M}())[2]
105105

106106

107-
Base.@propagate_inbounds Base.getindex(A::ArrayOfSimilarArrays{T,M,N}, idxs::Vararg{Any,N}) where {T,M,N} =
107+
Base.@propagate_inbounds Base.getindex(A::ArrayOfSimilarArrays{T,M,N}, idxs::Vararg{Integer,N}) where {T,M,N} =
108108
A.viewfunc(A.data, _ncolons(Val{M}())..., idxs...)
109109

110110

111-
Base.@propagate_inbounds Base.setindex!(A::ArrayOfSimilarArrays{T,M,N}, x::AbstractArray{U,M}, idxs::Vararg{Any,N}) where {T,M,N,U} =
111+
Base.@propagate_inbounds Base.setindex!(A::ArrayOfSimilarArrays{T,M,N}, x::AbstractArray{U,M}, idxs::Vararg{Integer,N}) where {T,M,N,U} =
112112
setindex!(A.data, x, _ncolons(Val{M}())..., idxs...)
113113

114114

@@ -177,6 +177,10 @@ VectorOfSimilarArrays(parent::AbstractArray{T,L}, viewfunc::VF = view) where {T,
177177
@inline Base.IndexStyle(V::VectorOfSimilarArrays) = IndexLinear()
178178

179179

180+
Base.@propagate_inbounds Base.getindex(A::VectorOfSimilarArrays{T,M}, rng::Union{Colon,UnitRange{<:Integer}}) where {T,M} =
181+
VectorOfSimilarArrays(A.viewfunc(A.data, _ncolons(Val{M}())..., rng), A.viewfunc)
182+
183+
180184
function Base.push!(V::VectorOfSimilarArrays{T,M}, x::AbstractArray{U,M}) where {T,M,U}
181185
size(x) != Base.front(size(V.data)) && throw(DimensionMismatch("Can't push, shape of source and elements of target is incompatible"))
182186
append!(V.data, x)

0 commit comments

Comments
 (0)