Skip to content

Commit b3d0fa8

Browse files
committed
Deprecate vectorized | in favor of compact broadcast syntax.
1 parent 3800c49 commit b3d0fa8

File tree

7 files changed

+32
-58
lines changed

7 files changed

+32
-58
lines changed

base/arraymath.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ promote_array_type{S<:Integer}(::typeof(/), ::Type{S}, ::Type{Bool}, T::Type) =
2828
promote_array_type{S<:Integer}(::typeof(\), ::Type{S}, ::Type{Bool}, T::Type) = T
2929
promote_array_type{S<:Integer}(F, ::Type{S}, ::Type{Bool}, T::Type) = T
3030

31-
for f in (:+, :-, :|)
31+
for f in (:+, :-)
3232
@eval function ($f)(A::AbstractArray, B::AbstractArray)
3333
promote_shape(A, B) # check size compatibility
3434
broadcast($f, A, B)
3535
end
3636
end
3737

38-
for f in (:|, :/, :\, :*, :+, :-)
38+
for f in (:/, :\, :*, :+, :-)
3939
if f != :/
4040
@eval ($f){T}(A::Number, B::AbstractArray{T}) = broadcast($f, A, B)
4141
end

base/bitarray.jl

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,31 +1237,6 @@ end
12371237
(/)(B::BitArray, x::Number) = (/)(Array(B), x)
12381238
(/)(x::Number, B::BitArray) = (/)(x, Array(B))
12391239

1240-
function (|)(B::BitArray, x::Bool)
1241-
x ? trues(size(B)) : copy(B)
1242-
end
1243-
(|)(x::Bool, B::BitArray) = B | x
1244-
1245-
for f in (:|,)
1246-
@eval begin
1247-
function ($f)(A::BitArray, B::BitArray)
1248-
F = BitArray(promote_shape(size(A),size(B))...)
1249-
Fc = F.chunks
1250-
Ac = A.chunks
1251-
Bc = B.chunks
1252-
(isempty(Ac) || isempty(Bc)) && return F
1253-
for i = 1:length(Fc)
1254-
Fc[i] = ($f)(Ac[i], Bc[i])
1255-
end
1256-
Fc[end] &= _msk_end(F)
1257-
return F
1258-
end
1259-
($f)(A::DenseArray{Bool}, B::BitArray) = ($f)(BitArray(A), B)
1260-
($f)(B::BitArray, A::DenseArray{Bool}) = ($f)(B, BitArray(A))
1261-
($f)(x::Number, B::BitArray) = ($f)(x, Array(B))
1262-
($f)(B::BitArray, x::Number) = ($f)(Array(B), x)
1263-
end
1264-
end
12651240

12661241
## promotion to complex ##
12671242

base/deprecated.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,4 +1428,11 @@ end
14281428
@deprecate (&)(A::AbstractArray, b::Number) A .& b
14291429
@deprecate (&)(A::AbstractArray, B::AbstractArray) A .& B
14301430

1431+
# Deprecate vectorized | in favor of compact broadcast syntax
1432+
@deprecate (|)(a::Bool, B::BitArray) a .| B
1433+
@deprecate (|)(A::BitArray, b::Bool) A .| b
1434+
@deprecate (|)(a::Number, B::AbstractArray) a .| B
1435+
@deprecate (|)(A::AbstractArray, b::Number) A .| b
1436+
@deprecate (|)(A::AbstractArray, B::AbstractArray) A .| B
1437+
14311438
# End deprecations scheduled for 0.6

base/sparse/sparsematrix.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,8 +1407,6 @@ conj!(A::SparseMatrixCSC) = (broadcast!(conj, A.nzval, A.nzval); A)
14071407
## Binary arithmetic and boolean operators
14081408
(+)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(+, A, B)
14091409
(-)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(-, A, B)
1410-
# TODO: Vectorized min, max, |, and xor should be deprecated in favor of compact-broadcast syntax.
1411-
(|)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(|, A, B)
14121410

14131411
( +)(A::SparseMatrixCSC, B::Array ) = Array(A) + B
14141412
( +)(A::Array , B::SparseMatrixCSC) = A + Array(B)

test/bitarray.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ timesofar("unary arithmetic")
781781
let b1 = bitrand(n1, n2)
782782
b2 = bitrand(n1, n2)
783783
@check_bit_operation broadcast(&, b1, b2) BitMatrix
784-
@check_bit_operation (|)(b1, b2) BitMatrix
784+
@check_bit_operation broadcast(|, b1, b2) BitMatrix
785785
@check_bit_operation broadcast(xor, b1, b2) BitMatrix
786786
@check_bit_operation (+)(b1, b2) Matrix{Int}
787787
@check_bit_operation (-)(b1, b2) Matrix{Int}
@@ -812,7 +812,7 @@ end
812812

813813
let b0 = falses(0)
814814
@check_bit_operation broadcast(&, b0, b0) BitVector
815-
@check_bit_operation (|)(b0, b0) BitVector
815+
@check_bit_operation broadcast(|, b0, b0) BitVector
816816
@check_bit_operation broadcast(xor, b0, b0) BitVector
817817
@check_bit_operation broadcast(*, b0, b0) BitVector
818818
@check_bit_operation (*)(b0, b0') Matrix{Int}
@@ -823,7 +823,7 @@ end
823823
let b1 = bitrand(n1, n2)
824824
i2 = rand(1:10, n1, n2)
825825
@check_bit_operation broadcast(&, b1, i2) Matrix{Int}
826-
@check_bit_operation (|)(b1, i2) Matrix{Int}
826+
@check_bit_operation broadcast(|, b1, i2) Matrix{Int}
827827
@check_bit_operation broadcast(xor, b1, i2) Matrix{Int}
828828
@check_bit_operation (+)(b1, i2) Matrix{Int}
829829
@check_bit_operation (-)(b1, i2) Matrix{Int}
@@ -856,14 +856,14 @@ let b2 = bitrand(n1, n2)
856856
cf1 = complex(f1)
857857

858858
@check_bit_operation broadcast(&, i1, b2) Matrix{Int}
859-
@check_bit_operation (|)(i1, b2) Matrix{Int}
859+
@check_bit_operation broadcast(|, i1, b2) Matrix{Int}
860860
@check_bit_operation broadcast(xor, i1, b2) Matrix{Int}
861861
@check_bit_operation broadcast(+, i1, b2) Matrix{Int}
862862
@check_bit_operation broadcast(-, i1, b2) Matrix{Int}
863863
@check_bit_operation broadcast(*, i1, b2) Matrix{Int}
864864

865865
@check_bit_operation broadcast(&, u1, b2) Matrix{UInt8}
866-
@check_bit_operation (|)(u1, b2) Matrix{UInt8}
866+
@check_bit_operation broadcast(|, u1, b2) Matrix{UInt8}
867867
@check_bit_operation broadcast(xor, u1, b2) Matrix{UInt8}
868868
@check_bit_operation broadcast(+, u1, b2) Matrix{UInt8}
869869
@check_bit_operation broadcast(-, u1, b2) Matrix{UInt8}
@@ -935,10 +935,10 @@ let b1 = bitrand(n1, n2)
935935
@check_bit_operation broadcast(&, b1, false) BitMatrix
936936
@check_bit_operation broadcast(&, true, b1) BitMatrix
937937
@check_bit_operation broadcast(&, false, b1) BitMatrix
938-
@check_bit_operation (|)(b1, true) BitMatrix
939-
@check_bit_operation (|)(b1, false) BitMatrix
940-
@check_bit_operation (|)(true, b1) BitMatrix
941-
@check_bit_operation (|)(false, b1) BitMatrix
938+
@check_bit_operation broadcast(|, b1, true) BitMatrix
939+
@check_bit_operation broadcast(|, b1, false) BitMatrix
940+
@check_bit_operation broadcast(|, true, b1) BitMatrix
941+
@check_bit_operation broadcast(|, false, b1) BitMatrix
942942
@check_bit_operation broadcast(xor, b1, true) BitMatrix
943943
@check_bit_operation broadcast(xor, b1, false) BitMatrix
944944
@check_bit_operation broadcast(xor, true, b1) BitMatrix
@@ -957,13 +957,13 @@ let b1 = bitrand(n1, n2)
957957
@check_bit_operation broadcast(mod,b1, true) BitMatrix
958958

959959
@check_bit_operation broadcast(&, b1, b2) BitMatrix
960-
@check_bit_operation (|)(b1, b2) BitMatrix
960+
@check_bit_operation broadcast(|, b1, b2) BitMatrix
961961
@check_bit_operation broadcast(xor, b1, b2) BitMatrix
962962
@check_bit_operation broadcast(&, b2, b1) BitMatrix
963-
@check_bit_operation (|)(b2, b1) BitMatrix
963+
@check_bit_operation broadcast(|, b2, b1) BitMatrix
964964
@check_bit_operation broadcast(xor, b2, b1) BitMatrix
965965
@check_bit_operation broadcast(&, b1, i2) Matrix{Int}
966-
@check_bit_operation (|)(b1, i2) Matrix{Int}
966+
@check_bit_operation broadcast(|, b1, i2) Matrix{Int}
967967
@check_bit_operation broadcast(xor, b1, i2) Matrix{Int}
968968
@check_bit_operation broadcast(+, b1, i2) Matrix{Int}
969969
@check_bit_operation broadcast(-, b1, i2) Matrix{Int}
@@ -973,7 +973,7 @@ let b1 = bitrand(n1, n2)
973973
@check_bit_operation broadcast(mod, b1, i2) Matrix{Int}
974974

975975
@check_bit_operation broadcast(&, b1, u2) Matrix{UInt8}
976-
@check_bit_operation (|)(b1, u2) Matrix{UInt8}
976+
@check_bit_operation broadcast(|, b1, u2) Matrix{UInt8}
977977
@check_bit_operation broadcast(xor, b1, u2) Matrix{UInt8}
978978
@check_bit_operation broadcast(+, b1, u2) Matrix{UInt8}
979979
@check_bit_operation broadcast(-, b1, u2) Matrix{UInt8}
@@ -1116,7 +1116,7 @@ let b1 = trues(v1)
11161116

11171117
for i = 3:(v1-1), j = 2:i
11181118
submask = b1 << (v1-j+1)
1119-
@test findnext((b1 >> i) | submask, j) == i+1
1119+
@test findnext((b1 >> i) .| submask, j) == i+1
11201120
@test findnextnot((~(b1 >> i)) .⊻ submask, j) == i+1
11211121
end
11221122
end
@@ -1273,7 +1273,7 @@ for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401]
12731273
@test map(identity, b1) == map(x->x, b1) == b1
12741274

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

12791279
@test map(^, b1, b2) == map((x,y)->x^y, b1, b2) == b1 .^ b2
@@ -1298,7 +1298,7 @@ for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401]
12981298
@test map!(one, b, b1) == map!(x->true, b, b1) == trues(l) == b
12991299

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

13041304
@test map!(^, b, b1, b2) == map!((x,y)->x^y, b, b1, b2) == b1 .^ b2 == b
@@ -1407,7 +1407,7 @@ for sz = [(n1,n1), (n1,n2), (n2,n1)], (f,isf) = [(tril,istril), (triu,istriu)]
14071407
end
14081408

14091409
let b1 = bitrand(n1,n1)
1410-
b1 |= b1.'
1410+
b1 .|= b1.'
14111411
@check_bit_operation issymmetric(b1) Bool
14121412
@check_bit_operation ishermitian(b1) Bool
14131413
end

test/reduce.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ prod2(itr) = invoke(prod, Tuple{Any}, itr)
186186
@test all(x->x>0, [4]) == true
187187
@test all(x->x>0, [-3, 4, 5]) == false
188188

189-
@test reduce(|, fill(trues(5), 24)) == trues(5)
190-
@test reduce(|, fill(falses(5), 24)) == falses(5)
189+
@test reduce((a, b) -> a .| b, fill(trues(5), 24)) == trues(5)
190+
@test reduce((a, b) -> a .| b, fill(falses(5), 24)) == falses(5)
191191
@test reduce((a, b) -> a .& b, fill(trues(5), 24)) == trues(5)
192192
@test reduce((a, b) -> a .& b, fill(falses(5), 24)) == falses(5)
193193

test/sparse/sparse.jl

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ do33 = ones(3)
3535
sqrfloatmat, colfloatmat = sprand(4, 4, 0.5), sprand(4, 1, 0.5)
3636
@test_throws DimensionMismatch (+)(sqrfloatmat, colfloatmat)
3737
@test_throws DimensionMismatch (-)(sqrfloatmat, colfloatmat)
38-
# @test_throws DimensionMismatch min(sqrfloatmat, colfloatmat) # vectorized min no longer exists
39-
# @test_throws DimensionMismatch max(sqrfloatmat, colfloatmat) # vectorized max no longer exists
40-
sqrboolmat, colboolmat = sprand(Bool, 4, 4, 0.5), sprand(Bool, 4, 1, 0.5)
41-
# @test_throws DimensionMismatch (&)(sqrboolmat, colboolmat) # vectorized & no longer exists
42-
@test_throws DimensionMismatch (|)(sqrboolmat, colboolmat)
43-
# @test_throws DimensionMismatch xor(sqrboolmat, colboolmat) # vectorized xor no longer exists
4438
end
4539
end
4640

@@ -1509,8 +1503,8 @@ end
15091503
@test broadcast(&, A13024, B13024) == sparse([1,2,5], [1,2,5], fill(true,3))
15101504
@test typeof(broadcast(&, A13024, B13024)) == SparseMatrixCSC{Bool,Int}
15111505

1512-
@test A13024 | B13024 == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6))
1513-
@test typeof(A13024 | B13024) == SparseMatrixCSC{Bool,Int}
1506+
@test broadcast(|, A13024, B13024) == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6))
1507+
@test typeof(broadcast(|, A13024, B13024)) == SparseMatrixCSC{Bool,Int}
15141508

15151509
@test broadcast(, A13024, B13024) == sparse([3,4,4], [3,3,4], fill(true,3), 5, 5)
15161510
@test typeof(broadcast(, A13024, B13024)) == SparseMatrixCSC{Bool,Int}
@@ -1521,10 +1515,10 @@ end
15211515
@test broadcast(min, A13024, B13024) == sparse([1,2,5], [1,2,5], fill(true,3))
15221516
@test typeof(broadcast(min, A13024, B13024)) == SparseMatrixCSC{Bool,Int}
15231517

1524-
for op in (+, -, |)
1518+
for op in (+, -)
15251519
@test op(A13024, B13024) == op(Array(A13024), Array(B13024))
15261520
end
1527-
for op in (max, min, &, xor)
1521+
for op in (max, min, &, |, xor)
15281522
@test op.(A13024, B13024) == op.(Array(A13024), Array(B13024))
15291523
end
15301524
end

0 commit comments

Comments
 (0)