Indexed assignment with logical indices: subarray.jl error


I have run into an error that I do not quite understand:

I have a BitArray whose entries I want to change based on another array

A = BitArray(rand(0:1, 3,3))
pos = randn(3,3)
A[pos .< 0]  .= 0

This yields the error message:

ERROR: ArgumentError: number of indices (1) must match the parent dimensionality (2)
[1] check_parent_index_match(parent::BitMatrix, #unused#::Tuple{Bool})
@ Base ./subarray.jl:43
[2] check_parent_index_match(parent::BitMatrix, indices::Tuple{Vector{Int64}})
@ Base ./subarray.jl:41
[3] SubArray
@ ./subarray.jl:21 [inlined]
[4] SubArray
@ ./subarray.jl:32 [inlined]
[5] SubArray
@ ./subarray.jl:28 [inlined]
[6] materialize!(B::Base.Broadcast.BitMaskedBitArray{2, 2}, bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}, Nothing, typeof(identity), Tuple{Int64}})
@ Base.Broadcast ./broadcast.jl:1174
[7] top-level scope
@ REPL[10]:1

The indexing works without an error, the error only appears when I try to assign the new value.

Thank you for any ideas!

This is a bug. Could you open an issue please?

Okay, thank you for the quick reply - will do!

Thanks! Ref #45903 and #45904.

1 Like