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 Jul 5, 2022
1 parent 95ea594 commit 89bdcce
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 @@ -1185,7 +1185,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 @@ -1116,6 +1116,14 @@ end
@inferred(test(x, y)) == [0, 0]
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

# test that `Broadcast` definition is defined as total and eligible for concrete evaluation
import Base.Broadcast: BroadcastStyle, DefaultArrayStyle
@test Base.infer_effects(BroadcastStyle, (DefaultArrayStyle{1},DefaultArrayStyle{2},)) |>
Expand Down

0 comments on commit 89bdcce

Please sign in to comment.