diff --git a/base/arraymath.jl b/base/arraymath.jl index e23d8829ad871..5b54bb3ed46a4 100644 --- a/base/arraymath.jl +++ b/base/arraymath.jl @@ -66,7 +66,7 @@ promote_array_type{S<:Integer}(::typeof(/), ::Type{S}, ::Type{Bool}, T::Type) = promote_array_type{S<:Integer}(::typeof(\), ::Type{S}, ::Type{Bool}, T::Type) = T promote_array_type{S<:Integer}(F, ::Type{S}, ::Type{Bool}, T::Type) = T -for f in (:+, :-, :div, :mod, :&, :|, :xor) +for f in (:+, :-, :div, :&, :|, :xor) @eval ($f)(A::AbstractArray, B::AbstractArray) = _elementwise($f, promote_eltype_op($f, A, B), A, B) end @@ -89,7 +89,7 @@ function _elementwise{T}(op, ::Type{T}, A::AbstractArray, B::AbstractArray) return F end -for f in (:div, :mod, :rem, :&, :|, :xor, :/, :\, :*, :+, :-) +for f in (:div, :rem, :&, :|, :xor, :/, :\, :*, :+, :-) if f != :/ @eval function ($f){T}(A::Number, B::AbstractArray{T}) R = promote_op($f, typeof(A), T) diff --git a/base/bitarray.jl b/base/bitarray.jl index 46a56ce9345fd..aad7932fb0af5 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1257,27 +1257,7 @@ function div(x::Number, B::BitArray) return fill(y, size(B)) end -function mod(A::BitArray, B::BitArray) - shp = promote_shape(size(A), size(B)) - all(B) || throw(DivideError()) - return falses(shp) -end -mod(A::BitArray, B::Array{Bool}) = mod(A, BitArray(B)) -mod(A::Array{Bool}, B::BitArray) = mod(BitArray(A), B) -function mod(B::BitArray, x::Bool) - return x ? falses(size(B)) : throw(DivideError()) -end -function mod(x::Bool, B::BitArray) - all(B) || throw(DivideError()) - return falses(size(B)) -end -function mod(x::Number, B::BitArray) - all(B) || throw(DivideError()) - y = mod(x, true) - return fill(y, size(B)) -end - -for f in (:div, :mod) +for f in (:div,) @eval begin function ($f)(B::BitArray, x::Number) T = promote_op($f, Bool, typeof(x)) diff --git a/base/deprecated.jl b/base/deprecated.jl index 02781b4948114..a8cc32b529254 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1168,4 +1168,11 @@ for (dep, f, op) in [(:sumabs!, :sum!, :abs), end end +# Deprecate manually vectorized mod methods in favor of compact broadcast syntax +@deprecate mod(B::BitArray, x::Bool) mod.(B, x) +@deprecate mod(x::Bool, B::BitArray) mod.(x, B) +@deprecate mod(A::AbstractArray, B::AbstractArray) mod.(A, B) +@deprecate mod{T}(x::Number, A::AbstractArray{T}) mod.(x, A) +@deprecate mod{T}(A::AbstractArray{T}, x::Number) mod.(A, x) + # End deprecations scheduled for 0.6 diff --git a/test/bitarray.jl b/test/bitarray.jl index 67f0be23d74e9..d8039a86d57b2 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -13,7 +13,7 @@ tc(r1,r2) = false bitcheck(b::BitArray) = Base._check_bitarray_consistency(b) bitcheck(x) = true -function check_bitop(ret_type, func, args...) +function check_bitop_call(ret_type, func, args...) r1 = func(args...) r2 = func(map(x->(isa(x, BitArray) ? Array(x) : x), args)...) ret_type ≢ nothing && !isa(r1, ret_type) && @show ret_type, r1 @@ -22,15 +22,13 @@ function check_bitop(ret_type, func, args...) @test isequal(r1, ret_type ≡ nothing ? r2 : convert(ret_type, r2)) @test bitcheck(r1) end - macro check_bit_operation(ex, ret_type) @assert Meta.isexpr(ex, :call) - Expr(:call, :check_bitop, esc(ret_type), map(esc,ex.args)...) + Expr(:call, :check_bitop_call, esc(ret_type), map(esc, ex.args)...) end - macro check_bit_operation(ex) @assert Meta.isexpr(ex, :call) - Expr(:call, :check_bitop, nothing, map(esc,ex.args)...) + Expr(:call, :check_bitop_call, nothing, map(esc,ex.args)...) end let t0 = time() @@ -794,11 +792,11 @@ let b1 = bitrand(n1, n2) b2 = trues(n1, n2) @check_bit_operation div(b1, b2) BitMatrix - @check_bit_operation mod(b1, b2) BitMatrix + @check_bit_operation broadcast(mod, b1, b2) BitMatrix @check_bit_operation div(b1,Array(b2)) BitMatrix - @check_bit_operation mod(b1,Array(b2)) BitMatrix + @check_bit_operation broadcast(mod, b1, Array(b2)) BitMatrix @check_bit_operation div(Array(b1),b2) BitMatrix - @check_bit_operation mod(Array(b1),b2) BitMatrix + @check_bit_operation broadcast(mod, Array(b1), b2) BitMatrix end let b1 = bitrand(n1, n1) @@ -833,7 +831,7 @@ let b1 = bitrand(n1, n2) @check_bit_operation broadcast(/, b1, i2) Matrix{Float64} @check_bit_operation broadcast(^, b1, i2) BitMatrix @check_bit_operation div(b1, i2) Matrix{Int} - @check_bit_operation mod(b1, i2) Matrix{Int} + @check_bit_operation broadcast(mod, b1, i2) Matrix{Int} end # Matrix{Bool}/Matrix{Float64} @@ -844,7 +842,7 @@ let b1 = bitrand(n1, n2) @check_bit_operation broadcast(/, b1, f2) Matrix{Float64} @check_bit_operation broadcast(^, b1, f2) Matrix{Float64} @check_bit_operation div(b1, f2) Matrix{Float64} - @check_bit_operation mod(b1, f2) Matrix{Float64} + @check_bit_operation broadcast(mod, b1, f2) Matrix{Float64} end # Number/Matrix @@ -883,22 +881,22 @@ let b2 = bitrand(n1, n2) b2 = trues(n1, n2) @check_bit_operation broadcast(/, true, b2) Matrix{Float64} @check_bit_operation div(true, b2) BitMatrix - @check_bit_operation mod(true, b2) BitMatrix + @check_bit_operation broadcast(mod, true, b2) BitMatrix @check_bit_operation broadcast(/, false, b2) Matrix{Float64} @check_bit_operation div(false, b2) BitMatrix - @check_bit_operation mod(false, b2) BitMatrix + @check_bit_operation broadcast(mod, false, b2) BitMatrix @check_bit_operation broadcast(/, i1, b2) Matrix{Float64} @check_bit_operation div(i1, b2) Matrix{Int} - @check_bit_operation mod(i1, b2) Matrix{Int} + @check_bit_operation broadcast(mod, i1, b2) Matrix{Int} @check_bit_operation broadcast(/, u1, b2) Matrix{Float64} @check_bit_operation div(u1, b2) Matrix{UInt8} - @check_bit_operation mod(u1, b2) Matrix{UInt8} + @check_bit_operation broadcast(mod, u1, b2) Matrix{UInt8} @check_bit_operation broadcast(/, f1, b2) Matrix{Float64} @check_bit_operation div(f1, b2) Matrix{Float64} - @check_bit_operation mod(f1, b2) Matrix{Float64} + @check_bit_operation broadcast(mod, f1, b2) Matrix{Float64} @check_bit_operation broadcast(/, ci1, b2) Matrix{Complex128} @check_bit_operation broadcast(/, cu1, b2) Matrix{Complex128} @@ -956,7 +954,7 @@ let b1 = bitrand(n1, n2) @check_bit_operation broadcast(/, b1, true) Matrix{Float64} @check_bit_operation broadcast(/, b1, false) Matrix{Float64} @check_bit_operation div(b1, true) BitMatrix - @check_bit_operation mod(b1, true) BitMatrix + @check_bit_operation broadcast(mod, b1, true) BitMatrix @check_bit_operation (&)(b1, b2) BitMatrix @check_bit_operation (|)(b1, b2) BitMatrix @@ -972,7 +970,7 @@ let b1 = bitrand(n1, n2) @check_bit_operation broadcast(*, b1, i2) Matrix{Int} @check_bit_operation broadcast(/, b1, i2) Matrix{Float64} @check_bit_operation div(b1, i2) Matrix{Int} - @check_bit_operation mod(b1, i2) Matrix{Int} + @check_bit_operation broadcast(mod, b1, i2) Matrix{Int} @check_bit_operation (&)(b1, u2) Matrix{UInt8} @check_bit_operation (|)(b1, u2) Matrix{UInt8} @@ -982,14 +980,14 @@ let b1 = bitrand(n1, n2) @check_bit_operation broadcast(*, b1, u2) Matrix{UInt8} @check_bit_operation broadcast(/, b1, u2) Matrix{Float64} @check_bit_operation div(b1, u2) Matrix{UInt8} - @check_bit_operation mod(b1, u2) Matrix{UInt8} + @check_bit_operation broadcast(mod, b1, u2) Matrix{UInt8} @check_bit_operation broadcast(+, b1, f2) Matrix{Float64} @check_bit_operation broadcast(-, b1, f2) Matrix{Float64} @check_bit_operation broadcast(*, b1, f2) Matrix{Float64} @check_bit_operation broadcast(/, b1, f2) Matrix{Float64} @check_bit_operation div(b1, f2) Matrix{Float64} - @check_bit_operation mod(b1, f2) Matrix{Float64} + @check_bit_operation broadcast(mod, b1, f2) Matrix{Float64} @check_bit_operation broadcast(+, b1, ci2) Matrix{Complex{Int}} @check_bit_operation broadcast(-, b1, ci2) Matrix{Complex{Int}}