Skip to content

Commit a0ea166

Browse files
committed
Implement logical indexing for SubArray. Fixes #4763
1 parent 287ace1 commit a0ea166

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

base/subarray.jl

+13
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,19 @@ function getindex(s::SubArray, is::Integer...)
263263
s.parent[index]
264264
end
265265

266+
function getindex{T}(s::SubArray{T,1}, I::AbstractVector{Bool})
267+
n = sum(I)
268+
out = similar(s, n)
269+
c = 1
270+
for i = 1:length(I)
271+
if I[i]
272+
out[c] = s[i]
273+
c += 1
274+
end
275+
end
276+
out
277+
end
278+
266279
getindex{T}(s::SubArray{T,1}, I::Range1{Int}) =
267280
getindex(s.parent, (s.first_index+(first(I)-1)*s.strides[1]):s.strides[1]:(s.first_index+(last(I)-1)*s.strides[1]))
268281

0 commit comments

Comments
 (0)