From a1e8113b1f9bad3f9894820830951f0ec0289185 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Tue, 25 Jul 2017 14:59:24 -0700 Subject: [PATCH 1/3] Deprecate remaining zero-preserving vectorized methods over SparseVectors. --- base/deprecated.jl | 9 +++++++++ base/sparse/sparsevector.jl | 11 ----------- test/sparse/sparsevector.jl | 35 +++++++++++++++++------------------ 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/base/deprecated.jl b/base/deprecated.jl index bd90c1497825d..f0f35b43bafab 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1565,6 +1565,15 @@ end # remove parse-with-chains-warn and bitshift-warn # update precedence table in doc/src/manual/mathematical-operations.md +# deprecate remaining vectorized methods over SparseVectors (zero-preserving) +for op in (:floor, :ceil, :trunc, :round, + :log1p, :expm1, :sinpi, + :sin, :tan, :sind, :tand, + :asin, :atan, :asind, :atand, + :sinh, :tanh, :asinh, :atanh) + @eval @deprecate ($op)(x::AbstractSparseVector{<:Number,<:Integer}) ($op).(x) +end + # PR #22182 @deprecate is_apple Sys.isapple @deprecate is_bsd Sys.isbsd diff --git a/base/sparse/sparsevector.jl b/base/sparse/sparsevector.jl index a3de2b2a45d58..bfaa0dab2e251 100644 --- a/base/sparse/sparsevector.jl +++ b/base/sparse/sparsevector.jl @@ -1063,17 +1063,6 @@ conj(x::SparseVector{<:Complex}) = SparseVector(length(x), copy(nonzeroinds(x)), imag(x::AbstractSparseVector{Tv,Ti}) where {Tv<:Real,Ti<:Integer} = SparseVector(length(x), Ti[], Tv[]) @unarymap_nz2z_z2z imag Complex -for op in [:floor, :ceil, :trunc, :round] - @eval @unarymap_nz2z_z2z $(op) Real -end - -for op in [:log1p, :expm1, - :sin, :tan, :sinpi, :sind, :tand, - :asin, :atan, :asind, :atand, - :sinh, :tanh, :asinh, :atanh] - @eval @unarymap_nz2z_z2z $(op) Number -end - # function that does not preserve zeros macro unarymap_z2nz(op, TF) diff --git a/test/sparse/sparsevector.jl b/test/sparse/sparsevector.jl index 04c4bcaf17e56..5c31beebaea12 100644 --- a/test/sparse/sparsevector.jl +++ b/test/sparse/sparsevector.jl @@ -656,24 +656,23 @@ end ### Zero-preserving math functions: sparse -> sparse -function check_nz2z_z2z(f::Function, x::SparseVector{T}, xf::Vector{T}) where T - R = typeof(f(zero(T))) - r = f(x) - isa(r, AbstractSparseVector) || error("$f(x) is not a sparse vector.") - eltype(r) == R || error("$f(x) results in eltype = $(eltype(r)), expect $R") - all(r.nzval .!= 0) || error("$f(x) contains zeros in nzval.") - Array(r) == f.(xf) || error("Incorrect results found in $f(x).") -end - -for f in [floor, ceil, trunc, round] - check_nz2z_z2z(f, rnd_x1, rnd_x1f) -end - -for f in [log1p, expm1, - sin, tan, sinpi, sind, tand, - asin, atan, asind, atand, - sinh, tanh, asinh, atanh] - check_nz2z_z2z(f, rnd_x0, rnd_x0f) +x1operations = (floor, ceil, trunc, round) +x0operations = (log1p, expm1, sinpi, + sin, tan, sind, tand, + asin, atan, asind, atand, + sinh, tanh, asinh, atanh) + +for (spvec, densevec, operations) in ( + (rnd_x0, rnd_x0f, x0operations), + (rnd_x1, rnd_x1f, x1operations) ) + for op in operations + spresvec = op.(spvec) + @test spresvec == op.(densevec) + @test all(!iszero, spresvec.nzval) + resvaltype = typeof(op(zero(eltype(spvec)))) + resindtype = Base.SparseArrays.indtype(spvec) + @test isa(spresvec, SparseVector{resvaltype,resindtype}) + end end ### Non-zero-preserving math functions: sparse -> dense From 2a6aedc8f8de2585a5be241c9cdd8245b7da3b19 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Tue, 25 Jul 2017 15:54:49 -0700 Subject: [PATCH 2/3] 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 f0f35b43bafab..415bfa7277c2b 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1573,6 +1573,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 From c6f1e373f2526f2f149683557036fc05db8340a2 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Sat, 5 Aug 2017 13:56:32 -0700 Subject: [PATCH 3/3] Add NEWS entry for deprecation of remaining vectorized methods and update news PR links. --- NEWS.md | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 104a4b49500ae..2596515ccedda 100644 --- a/NEWS.md +++ b/NEWS.md @@ -246,6 +246,10 @@ Deprecated or removed * The unexported type `AbstractIOBuffer` has been renamed to `GenericIOBuffer` ([#17360] [#22796]). + * Remaining vectorized methods over `SparseVector`s, particularly `floor`, `ceil`, + `trunc`, `round`, and most common transcendental functions such as `exp`, `log`, and + `sin` variants, have been deprecated in favor of dot-syntax ([#22961]). + * The method `String(io::IOBuffer)` is deprecated to `String(take!(copy(io)))` ([#21438]). * The function `readstring` is deprecated in favor of `read(io, String)` ([#22793]) @@ -885,7 +889,9 @@ Command-line option changes [#265]: https://github.com/JuliaLang/julia/issues/265 [#4615]: https://github.com/JuliaLang/julia/issues/4615 +[#6466]: https://github.com/JuliaLang/julia/issues/6466 [#7669]: https://github.com/JuliaLang/julia/issues/7669 +[#8470]: https://github.com/JuliaLang/julia/issues/8470 [#8974]: https://github.com/JuliaLang/julia/issues/8974 [#9343]: https://github.com/JuliaLang/julia/issues/9343 [#10946]: https://github.com/JuliaLang/julia/issues/10946 @@ -893,6 +899,7 @@ Command-line option changes [#11310]: https://github.com/JuliaLang/julia/issues/11310 [#12274]: https://github.com/JuliaLang/julia/issues/12274 [#12563]: https://github.com/JuliaLang/julia/issues/12563 +[#13079]: https://github.com/JuliaLang/julia/issues/13079 [#15850]: https://github.com/JuliaLang/julia/issues/15850 [#16213]: https://github.com/JuliaLang/julia/issues/16213 [#16378]: https://github.com/JuliaLang/julia/issues/16378 @@ -902,9 +909,11 @@ Command-line option changes [#16986]: https://github.com/JuliaLang/julia/issues/16986 [#17057]: https://github.com/JuliaLang/julia/issues/17057 [#17155]: https://github.com/JuliaLang/julia/issues/17155 +[#17240]: https://github.com/JuliaLang/julia/issues/17240 [#17261]: https://github.com/JuliaLang/julia/issues/17261 [#17265]: https://github.com/JuliaLang/julia/issues/17265 [#17302]: https://github.com/JuliaLang/julia/issues/17302 +[#17360]: https://github.com/JuliaLang/julia/issues/17360 [#17599]: https://github.com/JuliaLang/julia/issues/17599 [#17607]: https://github.com/JuliaLang/julia/issues/17607 [#17623]: https://github.com/JuliaLang/julia/issues/17623 @@ -932,6 +941,7 @@ Command-line option changes [#18628]: https://github.com/JuliaLang/julia/issues/18628 [#18642]: https://github.com/JuliaLang/julia/issues/18642 [#18644]: https://github.com/JuliaLang/julia/issues/18644 +[#18650]: https://github.com/JuliaLang/julia/issues/18650 [#18660]: https://github.com/JuliaLang/julia/issues/18660 [#18690]: https://github.com/JuliaLang/julia/issues/18690 [#18754]: https://github.com/JuliaLang/julia/issues/18754 @@ -944,6 +954,7 @@ Command-line option changes [#18977]: https://github.com/JuliaLang/julia/issues/18977 [#19018]: https://github.com/JuliaLang/julia/issues/19018 [#19088]: https://github.com/JuliaLang/julia/issues/19088 +[#19089]: https://github.com/JuliaLang/julia/issues/19089 [#19157]: https://github.com/JuliaLang/julia/issues/19157 [#19233]: https://github.com/JuliaLang/julia/issues/19233 [#19239]: https://github.com/JuliaLang/julia/issues/19239 @@ -1037,6 +1048,7 @@ Command-line option changes [#20500]: https://github.com/JuliaLang/julia/issues/20500 [#20530]: https://github.com/JuliaLang/julia/issues/20530 [#20543]: https://github.com/JuliaLang/julia/issues/20543 +[#20549]: https://github.com/JuliaLang/julia/issues/20549 [#20575]: https://github.com/JuliaLang/julia/issues/20575 [#20609]: https://github.com/JuliaLang/julia/issues/20609 [#20889]: https://github.com/JuliaLang/julia/issues/20889 @@ -1044,10 +1056,17 @@ Command-line option changes [#20974]: https://github.com/JuliaLang/julia/issues/20974 [#21183]: https://github.com/JuliaLang/julia/issues/21183 [#21359]: https://github.com/JuliaLang/julia/issues/21359 +[#21438]: https://github.com/JuliaLang/julia/issues/21438 +[#21450]: https://github.com/JuliaLang/julia/issues/21450 +[#21540]: https://github.com/JuliaLang/julia/issues/21540 +[#21592]: https://github.com/JuliaLang/julia/issues/21592 +[#21662]: https://github.com/JuliaLang/julia/issues/21662 [#21692]: https://github.com/JuliaLang/julia/issues/21692 [#21697]: https://github.com/JuliaLang/julia/issues/21697 +[#21709]: https://github.com/JuliaLang/julia/issues/21709 [#21746]: https://github.com/JuliaLang/julia/issues/21746 [#21759]: https://github.com/JuliaLang/julia/issues/21759 +[#21774]: https://github.com/JuliaLang/julia/issues/21774 [#21818]: https://github.com/JuliaLang/julia/issues/21818 [#21825]: https://github.com/JuliaLang/julia/issues/21825 [#21956]: https://github.com/JuliaLang/julia/issues/21956 @@ -1058,6 +1077,7 @@ Command-line option changes [#22038]: https://github.com/JuliaLang/julia/issues/22038 [#22062]: https://github.com/JuliaLang/julia/issues/22062 [#22064]: https://github.com/JuliaLang/julia/issues/22064 +[#22092]: https://github.com/JuliaLang/julia/issues/22092 [#22182]: https://github.com/JuliaLang/julia/issues/22182 [#22187]: https://github.com/JuliaLang/julia/issues/22187 [#22188]: https://github.com/JuliaLang/julia/issues/22188 @@ -1065,9 +1085,33 @@ Command-line option changes [#22224]: https://github.com/JuliaLang/julia/issues/22224 [#22228]: https://github.com/JuliaLang/julia/issues/22228 [#22245]: https://github.com/JuliaLang/julia/issues/22245 +[#22251]: https://github.com/JuliaLang/julia/issues/22251 +[#22274]: https://github.com/JuliaLang/julia/issues/22274 +[#22281]: https://github.com/JuliaLang/julia/issues/22281 +[#22296]: https://github.com/JuliaLang/julia/issues/22296 [#22310]: https://github.com/JuliaLang/julia/issues/22310 +[#22325]: https://github.com/JuliaLang/julia/issues/22325 +[#22350]: https://github.com/JuliaLang/julia/issues/22350 +[#22496]: https://github.com/JuliaLang/julia/issues/22496 [#22523]: https://github.com/JuliaLang/julia/issues/22523 [#22532]: https://github.com/JuliaLang/julia/issues/22532 -[#22709]: https://github.com/JuliaLang/julia/issues/22709 +[#22588]: https://github.com/JuliaLang/julia/issues/22588 +[#22605]: https://github.com/JuliaLang/julia/issues/22605 +[#22666]: https://github.com/JuliaLang/julia/issues/22666 +[#22703]: https://github.com/JuliaLang/julia/issues/22703 [#22712]: https://github.com/JuliaLang/julia/issues/22712 +[#22718]: https://github.com/JuliaLang/julia/issues/22718 +[#22723]: https://github.com/JuliaLang/julia/issues/22723 [#22732]: https://github.com/JuliaLang/julia/issues/22732 +[#22751]: https://github.com/JuliaLang/julia/issues/22751 +[#22762]: https://github.com/JuliaLang/julia/issues/22762 +[#22793]: https://github.com/JuliaLang/julia/issues/22793 +[#22796]: https://github.com/JuliaLang/julia/issues/22796 +[#22800]: https://github.com/JuliaLang/julia/issues/22800 +[#22814]: https://github.com/JuliaLang/julia/issues/22814 +[#22829]: https://github.com/JuliaLang/julia/issues/22829 +[#22847]: https://github.com/JuliaLang/julia/issues/22847 +[#22868]: https://github.com/JuliaLang/julia/issues/22868 +[#22925]: https://github.com/JuliaLang/julia/issues/22925 +[#22961]: https://github.com/JuliaLang/julia/issues/22961 +[#23035]: https://github.com/JuliaLang/julia/issues/23035