Matrix view based on BitVector?

I have a pre-allocated BitVector that fills randomly inside a loop. Based on that BitVector, I want to create a view of a Matrix but it allocates. Is there a workaround?

A simple example:

using Chairmarks
ix = BitVector(zeros(10)) # values change
x = rand(10, 10) # stays fixed

ix .= bitrand(10)
@b @views $x[$ix, $ix] 
58.412 ns (4 allocs: 224 bytes)

See:

2 Likes