Skip to content

Commit c031f5d

Browse files
committed
Fix indexing VectorOfArrays with logical indices
1 parent 4371227 commit c031f5d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/vector_of_arrays.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,13 @@ Base.@propagate_inbounds function Base._getindex(l::IndexStyle, A::VectorOfArray
212212
end
213213

214214

215-
Base.@propagate_inbounds function Base._getindex(l::IndexStyle, A::VectorOfArrays, idxs::AbstractVector{<:Integer})
216-
@boundscheck checkbounds(A, idxs)
215+
@inline _explicit_idxs(::AbstractVector, idxs::AbstractVector{<:Integer}) = idxs
216+
@inline _explicit_idxs(eachidx::AbstractVector, idxs::Base.LogicalIndex) = eachidx[idxs]
217+
218+
Base.@propagate_inbounds function Base._getindex(l::IndexStyle, A::VectorOfArrays, raw_idxs::AbstractVector{<:Integer})
219+
@boundscheck checkbounds(A, raw_idxs)
220+
221+
idxs = _explicit_idxs(eachindex(A), raw_idxs)
217222

218223
A_ep = A.elem_ptr
219224
A_data = A.data

test/vector_of_arrays.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
168168

169169
@test @inferred(element_ptr(V12)) == V12.elem_ptr
170170

171+
boolidxs = rand(Bool, length(V1))
172+
@test @inferred(V1[boolidxs]) == V1[eachindex(V1)[boolidxs]]
173+
174+
171175
## _view_reshape_spec not yet implemented ##
172176
# V1_copy = copy(V1)
173177
# V2_copy = copy(V2)

0 commit comments

Comments
 (0)