Skip to content

Commit

Permalink
Broadcast .* for BitArrays
Browse files Browse the repository at this point in the history
addresses #3171
  • Loading branch information
carlobaldassi committed Mar 3, 2014
1 parent bc7be5b commit 8bbfed8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 0 additions & 3 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1072,9 +1072,6 @@ function (.^){T<:Number}(B::BitArray, x::T)
end
end

(.*)(A::BitArray, B::BitArray) = A & B
(.*)(A::Array{Bool}, B::BitArray) = A & B
(.*)(B::BitArray, A::Array{Bool}) = A & B
(.*)(x::Bool, B::BitArray) = x & B
(.*)(B::BitArray, x::Bool) = B & x
(.*)(x::Number, B::BitArray) = x .* bitunpack(B)
Expand Down
12 changes: 12 additions & 0 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,16 @@ function (.^){T<:Integer}(A::BitArray, B::Array{T})
return F
end

for (sigA, sigB) in ((BitArray, BitArray),
(AbstractArray{Bool}, BitArray),
(BitArray, AbstractArray{Bool}))
@eval function (.*)(A::$sigA, B::$sigB)
try
return bitpack(A) & bitpack(B)
catch
return bitbroadcast(&, A, B)
end
end
end

end # module
1 change: 1 addition & 0 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ for arr in (identity, as_sub)
@test arr([1 2]) ./ arr([3, 4]) == [1/3 2/3; 1/4 2/4]
@test arr([1 2]) .\ arr([3, 4]) == [3 1.5; 4 2]
@test arr([3 4]) .^ arr([1, 2]) == [3 4; 9 16]
@test arr(bitpack([true false])) .* arr(bitpack([true, true])) == [true false; true false]
@test arr(bitpack([true false])) .^ arr(bitpack([false, true])) == [true true; true false]
@test arr(bitpack([true false])) .^ arr([0, 3]) == [true true; true false]

Expand Down

0 comments on commit 8bbfed8

Please sign in to comment.