Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cca20c5

Browse files
committedDec 25, 2016
Deprecate vectorized | in favor of compact broadcast syntax.
1 parent 9b414f2 commit cca20c5

File tree

7 files changed

+34
-32
lines changed

7 files changed

+34
-32
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, :&, :xor)
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, :&, :xor, :/, :\, :*, :+, :-)
9393
if f != :/
9494
@eval function ($f){T}(A::Number, B::AbstractArray{T})
9595
R = promote_op($f, typeof(A), T)

‎base/bitarray.jl

+1-6
Original file line numberDiff line numberDiff line change
@@ -1296,17 +1296,12 @@ function (&)(B::BitArray, x::Bool)
12961296
end
12971297
(&)(x::Bool, B::BitArray) = B & x
12981298

1299-
function (|)(B::BitArray, x::Bool)
1300-
x ? trues(size(B)) : copy(B)
1301-
end
1302-
(|)(x::Bool, B::BitArray) = B | x
1303-
13041299
function xor(B::BitArray, x::Bool)
13051300
x ? ~B : copy(B)
13061301
end
13071302
xor(x::Bool, B::BitArray) = xor(B, x)
13081303

1309-
for f in (:&, :|, :xor)
1304+
for f in (:&, :xor)
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 | in favor of compact broadcast syntax
1172+
@deprecate (|)(a::Bool, B::BitArray) a .| B
1173+
@deprecate (|)(A::BitArray, b::Bool) A .| b
1174+
@deprecate (|)(a::Number, B::AbstractArray) a .| B
1175+
@deprecate (|)(A::AbstractArray, b::Number) A .| b
1176+
@deprecate (|)(A::AbstractArray, B::AbstractArray) A .| B
1177+
11711178
# End deprecations scheduled for 0.6

‎base/sparse/sparsematrix.jl

-1
Original file line numberDiff line numberDiff line change
@@ -2289,7 +2289,6 @@ round{To}(::Type{To}, A::SparseMatrixCSC) = round.(To, A)
22892289
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)
2292-
(|)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(|, A, B)
22932292
xor(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(xor, A, B)
22942293

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

‎test/bitarray.jl

+17-17
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ timesofar("unary arithmetic")
783783
let b1 = bitrand(n1, n2)
784784
b2 = bitrand(n1, n2)
785785
@check_bit_operation (&)(b1, b2) BitMatrix
786-
@check_bit_operation (|)(b1, b2) BitMatrix
786+
@check_bit_operation broadcast(|, b1, b2) BitMatrix
787787
@check_bit_operation xor(b1, b2) BitMatrix
788788
@check_bit_operation (+)(b1, b2) Matrix{Int}
789789
@check_bit_operation (-)(b1, b2) Matrix{Int}
@@ -814,7 +814,7 @@ end
814814

815815
let b0 = falses(0)
816816
@check_bit_operation (&)(b0, b0) BitVector
817-
@check_bit_operation (|)(b0, b0) BitVector
817+
@check_bit_operation broadcast(|, b0, b0) BitVector
818818
@check_bit_operation xor(b0, b0) BitVector
819819
@check_bit_operation broadcast(*, b0, b0) BitVector
820820
@check_bit_operation (*)(b0, b0') Matrix{Int}
@@ -825,7 +825,7 @@ end
825825
let b1 = bitrand(n1, n2)
826826
i2 = rand(1:10, n1, n2)
827827
@check_bit_operation (&)(b1, i2) Matrix{Int}
828-
@check_bit_operation (|)(b1, i2) Matrix{Int}
828+
@check_bit_operation broadcast(|, b1, i2) Matrix{Int}
829829
@check_bit_operation xor(b1, i2) Matrix{Int}
830830
@check_bit_operation (+)(b1, i2) Matrix{Int}
831831
@check_bit_operation (-)(b1, i2) Matrix{Int}
@@ -858,14 +858,14 @@ let b2 = bitrand(n1, n2)
858858
cf1 = complex(f1)
859859

860860
@check_bit_operation (&)(i1, b2) Matrix{Int}
861-
@check_bit_operation (|)(i1, b2) Matrix{Int}
861+
@check_bit_operation broadcast(|, i1, b2) Matrix{Int}
862862
@check_bit_operation 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}
868-
@check_bit_operation (|)(u1, b2) Matrix{UInt8}
868+
@check_bit_operation broadcast(|, u1, b2) Matrix{UInt8}
869869
@check_bit_operation xor(u1, b2) Matrix{UInt8}
870870
@check_bit_operation broadcast(+, u1, b2) Matrix{UInt8}
871871
@check_bit_operation broadcast(-, u1, b2) Matrix{UInt8}
@@ -937,10 +937,10 @@ let b1 = bitrand(n1, n2)
937937
@check_bit_operation (&)(b1, false) BitMatrix
938938
@check_bit_operation (&)(true, b1) BitMatrix
939939
@check_bit_operation (&)(false, b1) BitMatrix
940-
@check_bit_operation (|)(b1, true) BitMatrix
941-
@check_bit_operation (|)(b1, false) BitMatrix
942-
@check_bit_operation (|)(true, b1) BitMatrix
943-
@check_bit_operation (|)(false, b1) BitMatrix
940+
@check_bit_operation broadcast(|, b1, true) BitMatrix
941+
@check_bit_operation broadcast(|, b1, false) BitMatrix
942+
@check_bit_operation broadcast(|, true, b1) BitMatrix
943+
@check_bit_operation broadcast(|, false, b1) BitMatrix
944944
@check_bit_operation xor(b1, true) BitMatrix
945945
@check_bit_operation xor(b1, false) BitMatrix
946946
@check_bit_operation xor(true, b1) BitMatrix
@@ -959,13 +959,13 @@ let b1 = bitrand(n1, n2)
959959
@check_bit_operation mod(b1, true) BitMatrix
960960

961961
@check_bit_operation (&)(b1, b2) BitMatrix
962-
@check_bit_operation (|)(b1, b2) BitMatrix
962+
@check_bit_operation broadcast(|, b1, b2) BitMatrix
963963
@check_bit_operation xor(b1, b2) BitMatrix
964964
@check_bit_operation (&)(b2, b1) BitMatrix
965-
@check_bit_operation (|)(b2, b1) BitMatrix
965+
@check_bit_operation broadcast(|, b2, b1) BitMatrix
966966
@check_bit_operation xor(b2, b1) BitMatrix
967967
@check_bit_operation (&)(b1, i2) Matrix{Int}
968-
@check_bit_operation (|)(b1, i2) Matrix{Int}
968+
@check_bit_operation broadcast(|, b1, i2) Matrix{Int}
969969
@check_bit_operation xor(b1, i2) Matrix{Int}
970970
@check_bit_operation broadcast(+, b1, i2) Matrix{Int}
971971
@check_bit_operation broadcast(-, b1, i2) Matrix{Int}
@@ -975,7 +975,7 @@ let b1 = bitrand(n1, n2)
975975
@check_bit_operation mod(b1, i2) Matrix{Int}
976976

977977
@check_bit_operation (&)(b1, u2) Matrix{UInt8}
978-
@check_bit_operation (|)(b1, u2) Matrix{UInt8}
978+
@check_bit_operation broadcast(|, b1, u2) Matrix{UInt8}
979979
@check_bit_operation xor(b1, u2) Matrix{UInt8}
980980
@check_bit_operation broadcast(+, b1, u2) Matrix{UInt8}
981981
@check_bit_operation broadcast(-, b1, u2) Matrix{UInt8}
@@ -1118,7 +1118,7 @@ let b1 = trues(v1)
11181118

11191119
for i = 3:(v1-1), j = 2:i
11201120
submask = b1 << (v1-j+1)
1121-
@test findnext((b1 >> i) | submask, j) == i+1
1121+
@test findnext((b1 >> i) .| submask, j) == i+1
11221122
@test findnextnot((~(b1 >> i)) submask, j) == i+1
11231123
end
11241124
end
@@ -1275,7 +1275,7 @@ for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401]
12751275
@test map(identity, b1) == map(x->x, b1) == b1
12761276

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

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

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

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

14111411
let b1 = bitrand(n1,n1)
1412-
b1 |= b1.'
1412+
b1 .|= b1.'
14131413
@check_bit_operation issymmetric(b1) Bool
14141414
@check_bit_operation ishermitian(b1) Bool
14151415
end

‎test/reduce.jl

+2-2
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(&, fill(trues(5), 24)) == trues(5)
192192
@test reduce(&, fill(falses(5), 24)) == falses(5)
193193

‎test/sparse/sparse.jl

+5-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ do33 = ones(3)
3939
@test_throws DimensionMismatch max(sqrfloatmat, colfloatmat)
4040
sqrboolmat, colboolmat = sprand(Bool, 4, 4, 0.5), sprand(Bool, 4, 1, 0.5)
4141
@test_throws DimensionMismatch (&)(sqrboolmat, colboolmat)
42-
@test_throws DimensionMismatch (|)(sqrboolmat, colboolmat)
42+
# @test_throws DimensionMismatch (|)(sqrboolmat, colboolmat) # vectorized | no longer exists
4343
@test_throws DimensionMismatch xor(sqrboolmat, colboolmat)
4444
end
4545
end
@@ -1592,8 +1592,8 @@ end
15921592
@test A13024 & B13024 == sparse([1,2,5], [1,2,5], fill(true,3))
15931593
@test typeof(A13024 & B13024) == SparseMatrixCSC{Bool,Int}
15941594

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

15981598
@test A13024 B13024 == sparse([3,4,4], [3,3,4], fill(true,3), 5, 5)
15991599
@test typeof(A13024 B13024) == SparseMatrixCSC{Bool,Int}
@@ -1604,7 +1604,8 @@ end
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(|, A13024, B13024) == broadcast(|, Array(A13024), Array(B13024))
1608+
for op in (+, -, &, xor)
16081609
@test op(A13024, B13024) == op(Array(A13024), Array(B13024))
16091610
end
16101611
for op in (max, min)

0 commit comments

Comments
 (0)
Please sign in to comment.