From 85c46b167b3a01aa3ba96165f14ca58120211927 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Tue, 25 Jul 2017 15:54:49 -0700 Subject: [PATCH] Deprecate remaining not-zero-preserving vectorized methods over SparseVectors. --- base/deprecated.jl | 8 ++++++++ base/sparse/sparsevector.jl | 10 ---------- test/sparse/sparsevector.jl | 26 ++++++++++++-------------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/base/deprecated.jl b/base/deprecated.jl index 54f8d480dc32c..8f24852ffe70b 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1577,6 +1577,14 @@ for op in (:floor, :ceil, :trunc, :round, :sinh, :tanh, :asinh, :atanh) @eval @deprecate ($op)(x::AbstractSparseVector{<:Number,<:Integer}) ($op).(x) end +# deprecate remaining vectorized methods over SparseVectors (not-zero-preserving) +for op in (:exp, :exp2, :exp10, :log, :log2, :log10, + :cos, :cosd, :acos, :cosh, :cospi, + :csc, :cscd, :acot, :csch, :acsch, + :cot, :cotd, :acosd, :coth, + :sec, :secd, :acotd, :sech, :asech) + @eval @deprecate ($op)(x::AbstractSparseVector{<:Number,<:Integer}) ($op).(x) +end # PR #22182 @deprecate is_apple Sys.isapple diff --git a/base/sparse/sparsevector.jl b/base/sparse/sparsevector.jl index bfaa0dab2e251..80225e4d328c8 100644 --- a/base/sparse/sparsevector.jl +++ b/base/sparse/sparsevector.jl @@ -1083,16 +1083,6 @@ macro unarymap_z2nz(op, TF) end) end -for op in [:exp, :exp2, :exp10, :log, :log2, :log10, - :cos, :csc, :cot, :sec, :cospi, - :cosd, :cscd, :cotd, :secd, - :acos, :acot, :acosd, :acotd, - :cosh, :csch, :coth, :sech, - :acsch, :asech] - @eval @unarymap_z2nz $(op) Number -end - - ### Binary Map # mode: diff --git a/test/sparse/sparsevector.jl b/test/sparse/sparsevector.jl index 5c31beebaea12..4a61940f53677 100644 --- a/test/sparse/sparsevector.jl +++ b/test/sparse/sparsevector.jl @@ -677,20 +677,18 @@ end ### Non-zero-preserving math functions: sparse -> dense -function check_z2nz(f::Function, x::SparseVector{T}, xf::Vector{T}) where T - R = typeof(f(zero(T))) - r = f(x) - isa(r, Vector) || error("$f(x) is not a dense vector.") - eltype(r) == R || error("$f(x) results in eltype = $(eltype(r)), expect $R") - r == f.(xf) || error("Incorrect results found in $f(x).") -end - -for f in [exp, exp2, exp10, log, log2, log10, - cos, csc, cot, sec, cospi, - cosd, cscd, cotd, secd, - acos, acot, acosd, acotd, - cosh, csch, coth, sech, acsch, asech] - check_z2nz(f, rnd_x0, rnd_x0f) +for op in (exp, exp2, exp10, log, log2, log10, + cos, cosd, acos, cosh, cospi, + csc, cscd, acot, csch, acsch, + cot, cotd, acosd, coth, + sec, secd, acotd, sech, asech) + spvec = rnd_x0 + densevec = rnd_x0f + spresvec = op.(spvec) + @test spresvec == op.(densevec) + resvaltype = typeof(op(zero(eltype(spvec)))) + resindtype = Base.SparseArrays.indtype(spvec) + @test isa(spresvec, SparseVector{resvaltype,resindtype}) end