Skip to content

Commit

Permalink
fix #45903, in place broadcast into a bit-masked bitmatrix (#45904)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbauman authored and KristofferC committed Dec 21, 2022
1 parent d7644bd commit 1e3f57b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ Base.@propagate_inbounds dotview(B::BitArray, i::BitArray) = BitMaskedBitArray(B
Base.show(io::IO, B::BitMaskedBitArray) = foreach(arg->show(io, arg), (typeof(B), (B.parent, B.mask)))
# Override materialize! to prevent the BitMaskedBitArray from escaping to an overrideable method
@inline materialize!(B::BitMaskedBitArray, bc::Broadcasted{<:Any,<:Any,typeof(identity),Tuple{Bool}}) = fill!(B, bc.args[1])
@inline materialize!(B::BitMaskedBitArray, bc::Broadcasted{<:Any}) = materialize!(SubArray(B.parent, to_indices(B.parent, (B.mask,))), bc)
@inline materialize!(B::BitMaskedBitArray, bc::Broadcasted{<:Any}) = materialize!(@inbounds(view(B.parent, B.mask)), bc)
function Base.fill!(B::BitMaskedBitArray, b::Bool)
Bc = B.parent.chunks
Ic = B.mask.chunks
Expand Down
8 changes: 8 additions & 0 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -993,3 +993,11 @@ end

@test Cyclotomic() .* [2, 3] == [[1, 2], [1, 2]]
end

@testset "issue #45903, in place broadcast into a bit-masked bitmatrix" begin
A = BitArray(ones(3,3))
pos = randn(3,3)
A[pos .< 0] .= false
@test all(>=(0), pos[A])
@test count(A) == count(>=(0), pos)
end

0 comments on commit 1e3f57b

Please sign in to comment.