Skip to content

Commit aaca49e

Browse files
committed
Deprecate manually vectorized mod methods in favor of compact broadcast syntax.
1 parent 44d7677 commit aaca49e

File tree

4 files changed

+28
-42
lines changed

4 files changed

+28
-42
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, :&, :|, :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, :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-21
Original file line numberDiff line numberDiff line change
@@ -1257,27 +1257,7 @@ function div(x::Number, B::BitArray)
12571257
return fill(y, size(B))
12581258
end
12591259

1260-
function mod(A::BitArray, B::BitArray)
1261-
shp = promote_shape(size(A), size(B))
1262-
all(B) || throw(DivideError())
1263-
return falses(shp)
1264-
end
1265-
mod(A::BitArray, B::Array{Bool}) = mod(A, BitArray(B))
1266-
mod(A::Array{Bool}, B::BitArray) = mod(BitArray(A), B)
1267-
function mod(B::BitArray, x::Bool)
1268-
return x ? falses(size(B)) : throw(DivideError())
1269-
end
1270-
function mod(x::Bool, B::BitArray)
1271-
all(B) || throw(DivideError())
1272-
return falses(size(B))
1273-
end
1274-
function mod(x::Number, B::BitArray)
1275-
all(B) || throw(DivideError())
1276-
y = mod(x, true)
1277-
return fill(y, size(B))
1278-
end
1279-
1280-
for f in (:div, :mod)
1260+
for f in (:div,)
12811261
@eval begin
12821262
function ($f)(B::BitArray, x::Number)
12831263
T = promote_op($f, Bool, typeof(x))

base/deprecated.jl

+8
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ macro vectorize_2arg(S,f)
10031003
end
10041004
export @vectorize_1arg, @vectorize_2arg
10051005

1006+
<<<<<<< HEAD
10061007
# deprecations for uses of old dot operators (.* etc) as objects, rather than
10071008
# just calling them infix.
10081009
for op in (:(!=), :, :+, :-, :*, :/, :÷, :%, :<, :(<=), :, :(==), :>, :>=, :, :\, :^, ://, :>>, :<<)
@@ -1168,4 +1169,11 @@ for (dep, f, op) in [(:sumabs!, :sum!, :abs),
11681169
end
11691170
end
11701171

1172+
# Deprecate manually vectorized mod methods in favor of compact broadcast syntax
1173+
@deprecate mod(B::BitArray, x::Bool) mod.(B, x)
1174+
@deprecate mod(x::Bool, B::BitArray) mod.(x, B)
1175+
@deprecate mod(A::AbstractArray, B::AbstractArray) mod.(A, B)
1176+
@deprecate mod{T}(x::Number, A::AbstractArray{T}) mod.(x, A)
1177+
@deprecate mod{T}(A::AbstractArray{T}, x::Number) mod.(A, x)
1178+
11711179
# End deprecations scheduled for 0.6

test/bitarray.jl

+17-19
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ tc(r1,r2) = false
1313
bitcheck(b::BitArray) = Base._check_bitarray_consistency(b)
1414
bitcheck(x) = true
1515

16-
function check_bitop(ret_type, func, args...)
16+
function check_bitop_call(ret_type, func, args...)
1717
r1 = func(args...)
1818
r2 = func(map(x->(isa(x, BitArray) ? Array(x) : x), args)...)
1919
ret_type nothing && !isa(r1, ret_type) && @show ret_type, r1
@@ -22,15 +22,13 @@ function check_bitop(ret_type, func, args...)
2222
@test isequal(r1, ret_type nothing ? r2 : convert(ret_type, r2))
2323
@test bitcheck(r1)
2424
end
25-
2625
macro check_bit_operation(ex, ret_type)
2726
@assert Meta.isexpr(ex, :call)
28-
Expr(:call, :check_bitop, esc(ret_type), map(esc,ex.args)...)
27+
Expr(:call, :check_bitop_call, esc(ret_type), map(esc, ex.args)...)
2928
end
30-
3129
macro check_bit_operation(ex)
3230
@assert Meta.isexpr(ex, :call)
33-
Expr(:call, :check_bitop, nothing, map(esc,ex.args)...)
31+
Expr(:call, :check_bitop_call, nothing, map(esc,ex.args)...)
3432
end
3533

3634
let t0 = time()
@@ -794,11 +792,11 @@ let b1 = bitrand(n1, n2)
794792

795793
b2 = trues(n1, n2)
796794
@check_bit_operation div(b1, b2) BitMatrix
797-
@check_bit_operation mod(b1, b2) BitMatrix
795+
@check_bit_operation broadcast(mod, b1, b2) BitMatrix
798796
@check_bit_operation div(b1,Array(b2)) BitMatrix
799-
@check_bit_operation mod(b1,Array(b2)) BitMatrix
797+
@check_bit_operation broadcast(mod, b1, Array(b2)) BitMatrix
800798
@check_bit_operation div(Array(b1),b2) BitMatrix
801-
@check_bit_operation mod(Array(b1),b2) BitMatrix
799+
@check_bit_operation broadcast(mod, Array(b1), b2) BitMatrix
802800
end
803801

804802
let b1 = bitrand(n1, n1)
@@ -833,7 +831,7 @@ let b1 = bitrand(n1, n2)
833831
@check_bit_operation broadcast(/, b1, i2) Matrix{Float64}
834832
@check_bit_operation broadcast(^, b1, i2) BitMatrix
835833
@check_bit_operation div(b1, i2) Matrix{Int}
836-
@check_bit_operation mod(b1, i2) Matrix{Int}
834+
@check_bit_operation broadcast(mod, b1, i2) Matrix{Int}
837835
end
838836

839837
# Matrix{Bool}/Matrix{Float64}
@@ -844,7 +842,7 @@ let b1 = bitrand(n1, n2)
844842
@check_bit_operation broadcast(/, b1, f2) Matrix{Float64}
845843
@check_bit_operation broadcast(^, b1, f2) Matrix{Float64}
846844
@check_bit_operation div(b1, f2) Matrix{Float64}
847-
@check_bit_operation mod(b1, f2) Matrix{Float64}
845+
@check_bit_operation broadcast(mod, b1, f2) Matrix{Float64}
848846
end
849847

850848
# Number/Matrix
@@ -883,22 +881,22 @@ let b2 = bitrand(n1, n2)
883881
b2 = trues(n1, n2)
884882
@check_bit_operation broadcast(/, true, b2) Matrix{Float64}
885883
@check_bit_operation div(true, b2) BitMatrix
886-
@check_bit_operation mod(true, b2) BitMatrix
884+
@check_bit_operation broadcast(mod, true, b2) BitMatrix
887885
@check_bit_operation broadcast(/, false, b2) Matrix{Float64}
888886
@check_bit_operation div(false, b2) BitMatrix
889-
@check_bit_operation mod(false, b2) BitMatrix
887+
@check_bit_operation broadcast(mod, false, b2) BitMatrix
890888

891889
@check_bit_operation broadcast(/, i1, b2) Matrix{Float64}
892890
@check_bit_operation div(i1, b2) Matrix{Int}
893-
@check_bit_operation mod(i1, b2) Matrix{Int}
891+
@check_bit_operation broadcast(mod, i1, b2) Matrix{Int}
894892

895893
@check_bit_operation broadcast(/, u1, b2) Matrix{Float64}
896894
@check_bit_operation div(u1, b2) Matrix{UInt8}
897-
@check_bit_operation mod(u1, b2) Matrix{UInt8}
895+
@check_bit_operation broadcast(mod, u1, b2) Matrix{UInt8}
898896

899897
@check_bit_operation broadcast(/, f1, b2) Matrix{Float64}
900898
@check_bit_operation div(f1, b2) Matrix{Float64}
901-
@check_bit_operation mod(f1, b2) Matrix{Float64}
899+
@check_bit_operation broadcast(mod, f1, b2) Matrix{Float64}
902900

903901
@check_bit_operation broadcast(/, ci1, b2) Matrix{Complex128}
904902
@check_bit_operation broadcast(/, cu1, b2) Matrix{Complex128}
@@ -956,7 +954,7 @@ let b1 = bitrand(n1, n2)
956954
@check_bit_operation broadcast(/, b1, true) Matrix{Float64}
957955
@check_bit_operation broadcast(/, b1, false) Matrix{Float64}
958956
@check_bit_operation div(b1, true) BitMatrix
959-
@check_bit_operation mod(b1, true) BitMatrix
957+
@check_bit_operation broadcast(mod, b1, true) BitMatrix
960958

961959
@check_bit_operation (&)(b1, b2) BitMatrix
962960
@check_bit_operation (|)(b1, b2) BitMatrix
@@ -972,7 +970,7 @@ let b1 = bitrand(n1, n2)
972970
@check_bit_operation broadcast(*, b1, i2) Matrix{Int}
973971
@check_bit_operation broadcast(/, b1, i2) Matrix{Float64}
974972
@check_bit_operation div(b1, i2) Matrix{Int}
975-
@check_bit_operation mod(b1, i2) Matrix{Int}
973+
@check_bit_operation broadcast(mod, b1, i2) Matrix{Int}
976974

977975
@check_bit_operation (&)(b1, u2) Matrix{UInt8}
978976
@check_bit_operation (|)(b1, u2) Matrix{UInt8}
@@ -982,14 +980,14 @@ let b1 = bitrand(n1, n2)
982980
@check_bit_operation broadcast(*, b1, u2) Matrix{UInt8}
983981
@check_bit_operation broadcast(/, b1, u2) Matrix{Float64}
984982
@check_bit_operation div(b1, u2) Matrix{UInt8}
985-
@check_bit_operation mod(b1, u2) Matrix{UInt8}
983+
@check_bit_operation broadcast(mod, b1, u2) Matrix{UInt8}
986984

987985
@check_bit_operation broadcast(+, b1, f2) Matrix{Float64}
988986
@check_bit_operation broadcast(-, b1, f2) Matrix{Float64}
989987
@check_bit_operation broadcast(*, b1, f2) Matrix{Float64}
990988
@check_bit_operation broadcast(/, b1, f2) Matrix{Float64}
991989
@check_bit_operation div(b1, f2) Matrix{Float64}
992-
@check_bit_operation mod(b1, f2) Matrix{Float64}
990+
@check_bit_operation broadcast(mod, b1, f2) Matrix{Float64}
993991

994992
@check_bit_operation broadcast(+, b1, ci2) Matrix{Complex{Int}}
995993
@check_bit_operation broadcast(-, b1, ci2) Matrix{Complex{Int}}

0 commit comments

Comments
 (0)