From 861d5861abb173882063b1908f58240d7cb2b6c3 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Sat, 17 Sep 2016 11:27:39 -0700 Subject: [PATCH] Deprecate manually vectorized abs2 methods in favor of compact broadcast syntax. --- base/deprecated.jl | 3 +++ base/sparse/sparsevector.jl | 3 ++- test/sparse/sparsevector.jl | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/base/deprecated.jl b/base/deprecated.jl index 661c16353b0dc..010742339811e 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1347,4 +1347,7 @@ function quadgk(args...) end export quadgk +# Deprecate manually vectorized abs2 methods in favor of compact broadcast syntax +@deprecate abs2(x::AbstractSparseVector) abs2.(x) + # End deprecations scheduled for 0.6 diff --git a/base/sparse/sparsevector.jl b/base/sparse/sparsevector.jl index 404a5f8ca5294..e2c1bfdbd24da 100644 --- a/base/sparse/sparsevector.jl +++ b/base/sparse/sparsevector.jl @@ -919,7 +919,8 @@ hvcat{T}(rows::Tuple{Vararg{Int}}, xs::_TypedDenseConcatGroup{T}...) = Base.type # zero-preserving functions (z->z, nz->nz) broadcast(::typeof(abs), x::AbstractSparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), abs.(nonzeros(x))) -for op in [:abs2, :conj] +broadcast(::typeof(abs2), x::AbstractSparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), abs2.(nonzeros(x))) +for op in [:conj] @eval begin $(op)(x::AbstractSparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), $(op).(nonzeros(x))) diff --git a/test/sparse/sparsevector.jl b/test/sparse/sparsevector.jl index 82c378fde39e8..bd5985e405fc5 100644 --- a/test/sparse/sparsevector.jl +++ b/test/sparse/sparsevector.jl @@ -588,7 +588,7 @@ let x = spv_x1, x2 = spv_x2 # abs and abs2 @test exact_equal(abs.(x), SparseVector(8, [2, 5, 6], abs.([1.25, -0.75, 3.5]))) - @test exact_equal(abs2(x), SparseVector(8, [2, 5, 6], abs2.([1.25, -0.75, 3.5]))) + @test exact_equal(abs2.(x), SparseVector(8, [2, 5, 6], abs2.([1.25, -0.75, 3.5]))) # plus and minus xa = SparseVector(8, [1,2,5,6,7], [3.25,5.25,-0.75,-2.0,-6.0]) @@ -610,7 +610,7 @@ let x = spv_x1, x2 = spv_x2 # multiplies xm = SparseVector(8, [2, 6], [5.0, -19.25]) let y=x # workaround for broadcast not preserving sparsity in general - @test exact_equal(x .* y, abs2(x)) + @test exact_equal(x .* y, abs2.(x)) end @test exact_equal(x .* x2, xm) @test exact_equal(x2 .* x, xm)