From 63be162e2d8c08d867e3b8572bda0e0ba9fc5953 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Tue, 24 Jan 2017 21:07:13 -0800 Subject: [PATCH] Deprecate vectorized sign methods in favor of dot syntax. --- base/arraymath.jl | 2 +- base/bitarray.jl | 2 +- base/deprecated.jl | 3 +++ test/arrayops.jl | 8 ++++---- test/bitarray.jl | 4 ++-- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/base/arraymath.jl b/base/arraymath.jl index 1e47fff0ddbb1..02a5067239dcf 100644 --- a/base/arraymath.jl +++ b/base/arraymath.jl @@ -11,7 +11,7 @@ See also [`conj`](@ref). """ conj!{T<:Number}(A::AbstractArray{T}) = (@inbounds broadcast!(conj, A, A); A) -for f in (:-, :~, :conj, :sign, :real, :imag) +for f in (:-, :~, :conj, :real, :imag) @eval ($f)(A::AbstractArray) = broadcast($f, A) end diff --git a/base/bitarray.jl b/base/bitarray.jl index 1a0c6b4940a89..585606a31b17f 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1166,7 +1166,7 @@ function (-)(B::BitArray) end return A end -sign(B::BitArray) = copy(B) +broadcast(sign, B::BitArray) = copy(B) function (~)(B::BitArray) C = similar(B) diff --git a/base/deprecated.jl b/base/deprecated.jl index 3f8a9f947a541..88b96527cbcb9 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1423,6 +1423,9 @@ end # Deprecate manually vectorized abs2 methods in favor of compact broadcast syntax @deprecate abs2(x::AbstractSparseVector) abs2.(x) +# Deprecate manually vectorized sign methods in favor of compact broadcast syntax +@deprecate sign(A::AbstractArray) sign.(A) + # Deprecate manually vectorized trigonometric and hyperbolic functions in favor of compact broadcast syntax for f in (:sec, :sech, :secd, :asec, :asech, :csc, :csch, :cscd, :acsc, :acsch, diff --git a/test/arrayops.jl b/test/arrayops.jl index 691dc7de3f160..49f19e468f89b 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -1824,10 +1824,10 @@ end B = [-10.0,0.0,3.0] C = [1,im,0] - @test sign(A) == [-1,0,1] - @test sign(B) == [-1,0,1] - @test typeof(sign(A)) == Vector{Int} - @test typeof(sign(B)) == Vector{Float64} + @test sign.(A) == [-1,0,1] + @test sign.(B) == [-1,0,1] + @test typeof(sign.(A)) == Vector{Int} + @test typeof(sign.(B)) == Vector{Float64} @test conj(A) == A @test conj(B) == A diff --git a/test/bitarray.jl b/test/bitarray.jl index 7112189d31c56..caa518eaab58b 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -724,7 +724,7 @@ timesofar("dequeue") @check_bit_operation (~)(b1) BitMatrix @check_bit_operation (!)(b1) BitMatrix @check_bit_operation (-)(b1) Matrix{Int} - @check_bit_operation sign(b1) BitMatrix + @check_bit_operation broadcast(sign, b1) BitMatrix @check_bit_operation real(b1) BitMatrix @check_bit_operation imag(b1) BitMatrix @check_bit_operation conj(b1) BitMatrix @@ -733,7 +733,7 @@ timesofar("dequeue") @check_bit_operation (~)(b0) BitVector @check_bit_operation (!)(b0) BitVector @check_bit_operation (-)(b0) Vector{Int} - @check_bit_operation sign(b0) BitVector + @check_bit_operation broadcast(sign, b0) BitVector @testset "flipbits!" begin b1 = bitrand(n1, n2)