Skip to content

Commit 309657f

Browse files
authored
Merge pull request #19711 from Sacha0/devecxor
Deprecate vectorized xor (⊻) in favor of compact broadcast syntax
2 parents 8ed946b + 8335884 commit 309657f

File tree

6 files changed

+31
-29
lines changed

6 files changed

+31
-29
lines changed

base/arraymath.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ promote_array_type{S<:Integer}(::typeof(/), ::Type{S}, ::Type{Bool}, T::Type) =
6666
promote_array_type{S<:Integer}(::typeof(\), ::Type{S}, ::Type{Bool}, T::Type) = T
6767
promote_array_type{S<:Integer}(F, ::Type{S}, ::Type{Bool}, T::Type) = T
6868

69-
for f in (:+, :-, :div, :mod, :&, :|, :xor)
69+
for f in (:+, :-, :div, :mod, :&, :|)
7070
@eval ($f)(A::AbstractArray, B::AbstractArray) =
7171
_elementwise($f, promote_eltype_op($f, A, B), A, B)
7272
end
@@ -89,7 +89,7 @@ function _elementwise{T}(op, ::Type{T}, A::AbstractArray, B::AbstractArray)
8989
return F
9090
end
9191

92-
for f in (:div, :mod, :rem, :&, :|, :xor, :/, :\, :*, :+, :-)
92+
for f in (:div, :mod, :rem, :&, :|, :/, :\, :*, :+, :-)
9393
if f != :/
9494
@eval ($f){T}(A::Number, B::AbstractArray{T}) = broadcast($f, A, B)
9595
end

base/bitarray.jl

+1-6
Original file line numberDiff line numberDiff line change
@@ -1301,12 +1301,7 @@ function (|)(B::BitArray, x::Bool)
13011301
end
13021302
(|)(x::Bool, B::BitArray) = B | x
13031303

1304-
function xor(B::BitArray, x::Bool)
1305-
x ? ~B : copy(B)
1306-
end
1307-
xor(x::Bool, B::BitArray) = xor(B, x)
1308-
1309-
for f in (:&, :|, :xor)
1304+
for f in (:&, :|)
13101305
@eval begin
13111306
function ($f)(A::BitArray, B::BitArray)
13121307
F = BitArray(promote_shape(size(A),size(B))...)

base/deprecated.jl

+7
Original file line numberDiff line numberDiff line change
@@ -1168,4 +1168,11 @@ for (dep, f, op) in [(:sumabs!, :sum!, :abs),
11681168
end
11691169
end
11701170

1171+
# Deprecate vectorized xor in favor of compact broadcast syntax
1172+
@deprecate xor(a::Bool, B::BitArray) xor.(a, B)
1173+
@deprecate xor(A::BitArray, b::Bool) xor.(A, b)
1174+
@deprecate xor(a::Number, B::AbstractArray) xor.(a, B)
1175+
@deprecate xor(A::AbstractArray, b::Number) xor.(A, b)
1176+
@deprecate xor(A::AbstractArray, B::AbstractArray) xor.(A, B)
1177+
11711178
# End deprecations scheduled for 0.6

base/sparse/sparsematrix.jl

-1
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,6 @@ min(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(min, A, B)
22902290
max(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(max, A, B)
22912291
(&)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(&, A, B)
22922292
(|)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(|, A, B)
2293-
xor(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(xor, A, B)
22942293

22952294
( +)(A::SparseMatrixCSC, B::Array ) = Array(A) + B
22962295
( +)(A::Array , B::SparseMatrixCSC) = A + Array(B)

test/bitarray.jl

+16-16
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ let b1 = bitrand(n1, n2)
784784
b2 = bitrand(n1, n2)
785785
@check_bit_operation (&)(b1, b2) BitMatrix
786786
@check_bit_operation (|)(b1, b2) BitMatrix
787-
@check_bit_operation xor(b1, b2) BitMatrix
787+
@check_bit_operation broadcast(xor, b1, b2) BitMatrix
788788
@check_bit_operation (+)(b1, b2) Matrix{Int}
789789
@check_bit_operation (-)(b1, b2) Matrix{Int}
790790
@check_bit_operation broadcast(*, b1, b2) BitMatrix
@@ -815,7 +815,7 @@ end
815815
let b0 = falses(0)
816816
@check_bit_operation (&)(b0, b0) BitVector
817817
@check_bit_operation (|)(b0, b0) BitVector
818-
@check_bit_operation xor(b0, b0) BitVector
818+
@check_bit_operation broadcast(xor, b0, b0) BitVector
819819
@check_bit_operation broadcast(*, b0, b0) BitVector
820820
@check_bit_operation (*)(b0, b0') Matrix{Int}
821821
end
@@ -826,7 +826,7 @@ let b1 = bitrand(n1, n2)
826826
i2 = rand(1:10, n1, n2)
827827
@check_bit_operation (&)(b1, i2) Matrix{Int}
828828
@check_bit_operation (|)(b1, i2) Matrix{Int}
829-
@check_bit_operation xor(b1, i2) Matrix{Int}
829+
@check_bit_operation broadcast(xor, b1, i2) Matrix{Int}
830830
@check_bit_operation (+)(b1, i2) Matrix{Int}
831831
@check_bit_operation (-)(b1, i2) Matrix{Int}
832832
@check_bit_operation broadcast(*, b1, i2) Matrix{Int}
@@ -859,14 +859,14 @@ let b2 = bitrand(n1, n2)
859859

860860
@check_bit_operation (&)(i1, b2) Matrix{Int}
861861
@check_bit_operation (|)(i1, b2) Matrix{Int}
862-
@check_bit_operation xor(i1, b2) Matrix{Int}
862+
@check_bit_operation broadcast(xor, i1, b2) Matrix{Int}
863863
@check_bit_operation broadcast(+, i1, b2) Matrix{Int}
864864
@check_bit_operation broadcast(-, i1, b2) Matrix{Int}
865865
@check_bit_operation broadcast(*, i1, b2) Matrix{Int}
866866

867867
@check_bit_operation (&)(u1, b2) Matrix{UInt8}
868868
@check_bit_operation (|)(u1, b2) Matrix{UInt8}
869-
@check_bit_operation xor(u1, b2) Matrix{UInt8}
869+
@check_bit_operation broadcast(xor, u1, b2) Matrix{UInt8}
870870
@check_bit_operation broadcast(+, u1, b2) Matrix{UInt8}
871871
@check_bit_operation broadcast(-, u1, b2) Matrix{UInt8}
872872
@check_bit_operation broadcast(*, u1, b2) Matrix{UInt8}
@@ -941,10 +941,10 @@ let b1 = bitrand(n1, n2)
941941
@check_bit_operation (|)(b1, false) BitMatrix
942942
@check_bit_operation (|)(true, b1) BitMatrix
943943
@check_bit_operation (|)(false, b1) BitMatrix
944-
@check_bit_operation xor(b1, true) BitMatrix
945-
@check_bit_operation xor(b1, false) BitMatrix
946-
@check_bit_operation xor(true, b1) BitMatrix
947-
@check_bit_operation xor(false, b1) BitMatrix
944+
@check_bit_operation broadcast(xor, b1, true) BitMatrix
945+
@check_bit_operation broadcast(xor, b1, false) BitMatrix
946+
@check_bit_operation broadcast(xor, true, b1) BitMatrix
947+
@check_bit_operation broadcast(xor, false, b1) BitMatrix
948948
@check_bit_operation broadcast(+, b1, true) Matrix{Int}
949949
@check_bit_operation broadcast(+, b1, false) Matrix{Int}
950950
@check_bit_operation broadcast(-, b1, true) Matrix{Int}
@@ -960,13 +960,13 @@ let b1 = bitrand(n1, n2)
960960

961961
@check_bit_operation (&)(b1, b2) BitMatrix
962962
@check_bit_operation (|)(b1, b2) BitMatrix
963-
@check_bit_operation xor(b1, b2) BitMatrix
963+
@check_bit_operation broadcast(xor, b1, b2) BitMatrix
964964
@check_bit_operation (&)(b2, b1) BitMatrix
965965
@check_bit_operation (|)(b2, b1) BitMatrix
966-
@check_bit_operation xor(b2, b1) BitMatrix
966+
@check_bit_operation broadcast(xor, b2, b1) BitMatrix
967967
@check_bit_operation (&)(b1, i2) Matrix{Int}
968968
@check_bit_operation (|)(b1, i2) Matrix{Int}
969-
@check_bit_operation xor(b1, i2) Matrix{Int}
969+
@check_bit_operation broadcast(xor, b1, i2) Matrix{Int}
970970
@check_bit_operation broadcast(+, b1, i2) Matrix{Int}
971971
@check_bit_operation broadcast(-, b1, i2) Matrix{Int}
972972
@check_bit_operation broadcast(*, b1, i2) Matrix{Int}
@@ -976,7 +976,7 @@ let b1 = bitrand(n1, n2)
976976

977977
@check_bit_operation (&)(b1, u2) Matrix{UInt8}
978978
@check_bit_operation (|)(b1, u2) Matrix{UInt8}
979-
@check_bit_operation xor(b1, u2) Matrix{UInt8}
979+
@check_bit_operation broadcast(xor, b1, u2) Matrix{UInt8}
980980
@check_bit_operation broadcast(+, b1, u2) Matrix{UInt8}
981981
@check_bit_operation broadcast(-, b1, u2) Matrix{UInt8}
982982
@check_bit_operation broadcast(*, b1, u2) Matrix{UInt8}
@@ -1119,7 +1119,7 @@ let b1 = trues(v1)
11191119
for i = 3:(v1-1), j = 2:i
11201120
submask = b1 << (v1-j+1)
11211121
@test findnext((b1 >> i) | submask, j) == i+1
1122-
@test findnextnot((~(b1 >> i)) submask, j) == i+1
1122+
@test findnextnot((~(b1 >> i)) . submask, j) == i+1
11231123
end
11241124
end
11251125

@@ -1276,7 +1276,7 @@ for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401]
12761276

12771277
@test map(&, b1, b2) == map((x,y)->x&y, b1, b2) == b1 & b2
12781278
@test map(|, b1, b2) == map((x,y)->x|y, b1, b2) == b1 | b2
1279-
@test map(, b1, b2) == map((x,y)->xy, b1, b2) == b1 b2 == xor(b1, b2)
1279+
@test map(, b1, b2) == map((x,y)->xy, b1, b2) == broadcast(, b1, b2) == broadcast(xor, b1, b2)
12801280

12811281
@test map(^, b1, b2) == map((x,y)->x^y, b1, b2) == b1 .^ b2
12821282
@test map(*, b1, b2) == map((x,y)->x*y, b1, b2) == b1 .* b2
@@ -1301,7 +1301,7 @@ for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401]
13011301

13021302
@test map!(&, b, b1, b2) == map!((x,y)->x&y, b, b1, b2) == b1 & b2 == b
13031303
@test map!(|, b, b1, b2) == map!((x,y)->x|y, b, b1, b2) == b1 | b2 == b
1304-
@test map!(, b, b1, b2) == map!((x,y)->xy, b, b1, b2) == b1 b2 == xor(b1, b2) == b
1304+
@test map!(, b, b1, b2) == map!((x,y)->xy, b, b1, b2) == broadcast(, b1, b2) == broadcast(xor, b1, b2) == b
13051305

13061306
@test map!(^, b, b1, b2) == map!((x,y)->x^y, b, b1, b2) == b1 .^ b2 == b
13071307
@test map!(*, b, b1, b2) == map!((x,y)->x*y, b, b1, b2) == b1 .* b2 == b

test/sparse/sparse.jl

+5-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ do33 = ones(3)
4040
sqrboolmat, colboolmat = sprand(Bool, 4, 4, 0.5), sprand(Bool, 4, 1, 0.5)
4141
@test_throws DimensionMismatch (&)(sqrboolmat, colboolmat)
4242
@test_throws DimensionMismatch (|)(sqrboolmat, colboolmat)
43-
@test_throws DimensionMismatch xor(sqrboolmat, colboolmat)
43+
# @test_throws DimensionMismatch xor(sqrboolmat, colboolmat) # vectorized xor no longer exists
4444
end
4545
end
4646

@@ -1595,16 +1595,17 @@ end
15951595
@test A13024 | B13024 == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6))
15961596
@test typeof(A13024 | B13024) == SparseMatrixCSC{Bool,Int}
15971597

1598-
@test A13024 B13024 == sparse([3,4,4], [3,3,4], fill(true,3), 5, 5)
1599-
@test typeof(A13024 B13024) == SparseMatrixCSC{Bool,Int}
1598+
@test broadcast(, A13024, B13024) == sparse([3,4,4], [3,3,4], fill(true,3), 5, 5)
1599+
@test typeof(broadcast(, A13024, B13024)) == SparseMatrixCSC{Bool,Int}
16001600

16011601
@test max(A13024, B13024) == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6))
16021602
@test typeof(max(A13024, B13024)) == SparseMatrixCSC{Bool,Int}
16031603

16041604
@test min(A13024, B13024) == sparse([1,2,5], [1,2,5], fill(true,3))
16051605
@test typeof(min(A13024, B13024)) == SparseMatrixCSC{Bool,Int}
16061606

1607-
for op in (+, -, &, |, xor)
1607+
@test broadcast(xor, A13024, B13024) == broadcast(xor, Array(A13024), Array(B13024))
1608+
for op in (+, -, &, |)
16081609
@test op(A13024, B13024) == op(Array(A13024), Array(B13024))
16091610
end
16101611
for op in (max, min)

0 commit comments

Comments
 (0)