Skip to content

Commit 340574a

Browse files
committed
Deprecate manually vectorized div methods in favor of compact broadcast syntax.
1 parent 44d7677 commit 340574a

File tree

5 files changed

+33
-32
lines changed

5 files changed

+33
-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 (:+, :-, :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 (: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

+7-9
Original file line numberDiff line numberDiff line change
@@ -1237,21 +1237,19 @@ end
12371237
(/)(B::BitArray, x::Number) = (/)(Array(B), x)
12381238
(/)(x::Number, B::BitArray) = (/)(x, Array(B))
12391239

1240-
function div(A::BitArray, B::BitArray)
1240+
function broadcast(::typeof(div), A::BitArray, B::BitArray)
12411241
shp = promote_shape(size(A), size(B))
12421242
all(B) || throw(DivideError())
12431243
return reshape(copy(A), shp)
12441244
end
1245-
div(A::BitArray, B::Array{Bool}) = div(A, BitArray(B))
1246-
div(A::Array{Bool}, B::BitArray) = div(BitArray(A), B)
1247-
function div(B::BitArray, x::Bool)
1248-
return x ? copy(B) : throw(DivideError())
1249-
end
1250-
function div(x::Bool, B::BitArray)
1245+
broadcast(::typeof(div), A::BitArray, B::Array{Bool}) = div.(A, BitArray(B))
1246+
broadcast(::typeof(div), A::Array{Bool}, B::BitArray) = div.(BitArray(A), B)
1247+
broadcast(::typeof(div), B::BitArray, x::Bool) = x ? copy(B) : throw(DivideError())
1248+
function broadcast(::typeof(div), x::Bool, B::BitArray)
12511249
all(B) || throw(DivideError())
12521250
return x ? trues(size(B)) : falses(size(B))
12531251
end
1254-
function div(x::Number, B::BitArray)
1252+
function broadcast(::typeof(div), x::Number, B::BitArray)
12551253
all(B) || throw(DivideError())
12561254
y = div(x, true)
12571255
return fill(y, size(B))
@@ -1277,7 +1275,7 @@ function mod(x::Number, B::BitArray)
12771275
return fill(y, size(B))
12781276
end
12791277

1280-
for f in (:div, :mod)
1278+
for f in (:mod,)
12811279
@eval begin
12821280
function ($f)(B::BitArray, x::Number)
12831281
T = promote_op($f, Bool, typeof(x))

base/deprecated.jl

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

1171+
# Deprecate manually vectorized div methods in favor of compact broadcast syntax
1172+
@deprecate div(A::Number, B::AbstractArray) div.(A, B)
1173+
@deprecate div(A::AbstractArray, B::Number) div.(A, B)
1174+
@deprecate div(A::AbstractArray, B::AbstractArray) div.(A, B)
1175+
11711176
# End deprecations scheduled for 0.6

base/dft.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ plan_irfft
354354

355355
export fftshift, ifftshift
356356

357-
fftshift(x) = circshift(x, div([size(x)...],2))
357+
fftshift(x) = circshift(x, div.([size(x)...],2))
358358

359359
"""
360360
fftshift(x)
@@ -376,7 +376,7 @@ Swap the first and second halves of the given dimension of array `x`.
376376
"""
377377
fftshift(x,dim)
378378

379-
ifftshift(x) = circshift(x, div([size(x)...],-2))
379+
ifftshift(x) = circshift(x, div.([size(x)...],-2))
380380

381381
"""
382382
ifftshift(x, [dim])

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()
@@ -793,11 +791,11 @@ let b1 = bitrand(n1, n2)
793791
@check_bit_operation (/)(b1,1) Matrix{Float64}
794792

795793
b2 = trues(n1, n2)
796-
@check_bit_operation div(b1, b2) BitMatrix
794+
@check_bit_operation broadcast(div, b1, b2) BitMatrix
797795
@check_bit_operation mod(b1, b2) BitMatrix
798-
@check_bit_operation div(b1,Array(b2)) BitMatrix
796+
@check_bit_operation broadcast(div, b1, Array(b2)) BitMatrix
799797
@check_bit_operation mod(b1,Array(b2)) BitMatrix
800-
@check_bit_operation div(Array(b1),b2) BitMatrix
798+
@check_bit_operation broadcast(div, Array(b1), b2) BitMatrix
801799
@check_bit_operation mod(Array(b1),b2) BitMatrix
802800
end
803801

@@ -832,7 +830,7 @@ let b1 = bitrand(n1, n2)
832830
@check_bit_operation broadcast(*, b1, i2) Matrix{Int}
833831
@check_bit_operation broadcast(/, b1, i2) Matrix{Float64}
834832
@check_bit_operation broadcast(^, b1, i2) BitMatrix
835-
@check_bit_operation div(b1, i2) Matrix{Int}
833+
@check_bit_operation broadcast(div, b1, i2) Matrix{Int}
836834
@check_bit_operation mod(b1, i2) Matrix{Int}
837835
end
838836

@@ -843,7 +841,7 @@ let b1 = bitrand(n1, n2)
843841
@check_bit_operation broadcast(*, b1, f2) Matrix{Float64}
844842
@check_bit_operation broadcast(/, b1, f2) Matrix{Float64}
845843
@check_bit_operation broadcast(^, b1, f2) Matrix{Float64}
846-
@check_bit_operation div(b1, f2) Matrix{Float64}
844+
@check_bit_operation broadcast(div, b1, f2) Matrix{Float64}
847845
@check_bit_operation mod(b1, f2) Matrix{Float64}
848846
end
849847

@@ -882,22 +880,22 @@ let b2 = bitrand(n1, n2)
882880

883881
b2 = trues(n1, n2)
884882
@check_bit_operation broadcast(/, true, b2) Matrix{Float64}
885-
@check_bit_operation div(true, b2) BitMatrix
883+
@check_bit_operation broadcast(div, true, b2) BitMatrix
886884
@check_bit_operation mod(true, b2) BitMatrix
887885
@check_bit_operation broadcast(/, false, b2) Matrix{Float64}
888-
@check_bit_operation div(false, b2) BitMatrix
886+
@check_bit_operation broadcast(div, false, b2) BitMatrix
889887
@check_bit_operation mod(false, b2) BitMatrix
890888

891889
@check_bit_operation broadcast(/, i1, b2) Matrix{Float64}
892-
@check_bit_operation div(i1, b2) Matrix{Int}
890+
@check_bit_operation broadcast(div, i1, b2) Matrix{Int}
893891
@check_bit_operation mod(i1, b2) Matrix{Int}
894892

895893
@check_bit_operation broadcast(/, u1, b2) Matrix{Float64}
896-
@check_bit_operation div(u1, b2) Matrix{UInt8}
894+
@check_bit_operation broadcast(div, u1, b2) Matrix{UInt8}
897895
@check_bit_operation mod(u1, b2) Matrix{UInt8}
898896

899897
@check_bit_operation broadcast(/, f1, b2) Matrix{Float64}
900-
@check_bit_operation div(f1, b2) Matrix{Float64}
898+
@check_bit_operation broadcast(div, f1, b2) Matrix{Float64}
901899
@check_bit_operation mod(f1, b2) Matrix{Float64}
902900

903901
@check_bit_operation broadcast(/, ci1, b2) Matrix{Complex128}
@@ -955,7 +953,7 @@ let b1 = bitrand(n1, n2)
955953
@check_bit_operation broadcast(*, false, b1) BitMatrix
956954
@check_bit_operation broadcast(/, b1, true) Matrix{Float64}
957955
@check_bit_operation broadcast(/, b1, false) Matrix{Float64}
958-
@check_bit_operation div(b1, true) BitMatrix
956+
@check_bit_operation broadcast(div, b1, true) BitMatrix
959957
@check_bit_operation mod(b1, true) BitMatrix
960958

961959
@check_bit_operation (&)(b1, b2) BitMatrix
@@ -971,7 +969,7 @@ let b1 = bitrand(n1, n2)
971969
@check_bit_operation broadcast(-, b1, i2) Matrix{Int}
972970
@check_bit_operation broadcast(*, b1, i2) Matrix{Int}
973971
@check_bit_operation broadcast(/, b1, i2) Matrix{Float64}
974-
@check_bit_operation div(b1, i2) Matrix{Int}
972+
@check_bit_operation broadcast(div, b1, i2) Matrix{Int}
975973
@check_bit_operation mod(b1, i2) Matrix{Int}
976974

977975
@check_bit_operation (&)(b1, u2) Matrix{UInt8}
@@ -981,14 +979,14 @@ let b1 = bitrand(n1, n2)
981979
@check_bit_operation broadcast(-, b1, u2) Matrix{UInt8}
982980
@check_bit_operation broadcast(*, b1, u2) Matrix{UInt8}
983981
@check_bit_operation broadcast(/, b1, u2) Matrix{Float64}
984-
@check_bit_operation div(b1, u2) Matrix{UInt8}
982+
@check_bit_operation broadcast(div, b1, u2) Matrix{UInt8}
985983
@check_bit_operation 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}
991-
@check_bit_operation div(b1, f2) Matrix{Float64}
989+
@check_bit_operation broadcast(div, b1, f2) Matrix{Float64}
992990
@check_bit_operation mod(b1, f2) Matrix{Float64}
993991

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

0 commit comments

Comments
 (0)