Skip to content

Commit af2764a

Browse files
mbaumanKristofferC
authored andcommitted
fix #45903, in place broadcast into a bit-masked bitmatrix (#45904)
as reported in https://discourse.julialang.org/t/indexed-assignment-with-logical-indices-subarray-jl-error/83646 (cherry picked from commit 89bdcce)
1 parent 8682e25 commit af2764a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

base/broadcast.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ Base.@propagate_inbounds dotview(B::BitArray, i::BitArray) = BitMaskedBitArray(B
11831183
Base.show(io::IO, B::BitMaskedBitArray) = foreach(arg->show(io, arg), (typeof(B), (B.parent, B.mask)))
11841184
# Override materialize! to prevent the BitMaskedBitArray from escaping to an overrideable method
11851185
@inline materialize!(B::BitMaskedBitArray, bc::Broadcasted{<:Any,<:Any,typeof(identity),Tuple{Bool}}) = fill!(B, bc.args[1])
1186-
@inline materialize!(B::BitMaskedBitArray, bc::Broadcasted{<:Any}) = materialize!(SubArray(B.parent, to_indices(B.parent, (B.mask,))), bc)
1186+
@inline materialize!(B::BitMaskedBitArray, bc::Broadcasted{<:Any}) = materialize!(@inbounds(view(B.parent, B.mask)), bc)
11871187
function Base.fill!(B::BitMaskedBitArray, b::Bool)
11881188
Bc = B.parent.chunks
11891189
Ic = B.mask.chunks

test/broadcast.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,3 +993,11 @@ end
993993

994994
@test Cyclotomic() .* [2, 3] == [[1, 2], [1, 2]]
995995
end
996+
997+
@testset "issue #45903, in place broadcast into a bit-masked bitmatrix" begin
998+
A = BitArray(ones(3,3))
999+
pos = randn(3,3)
1000+
A[pos .< 0] .= false
1001+
@test all(>=(0), pos[A])
1002+
@test count(A) == count(>=(0), pos)
1003+
end

0 commit comments

Comments
 (0)