Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crush the vectorized method resistance #22961

Merged
merged 3 commits into from
Aug 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -885,14 +889,17 @@ Command-line option changes
<!--- generated by NEWS-update.jl: -->
[#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
[#11250]: https://github.com/JuliaLang/julia/issues/11250
[#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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -1037,17 +1048,25 @@ 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
[#20952]: https://github.com/JuliaLang/julia/issues/20952
[#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
Expand All @@ -1058,16 +1077,41 @@ 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
[#22210]: https://github.com/JuliaLang/julia/issues/22210
[#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
17 changes: 17 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,23 @@ 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
# 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
@deprecate is_bsd Sys.isbsd
Expand Down
21 changes: 0 additions & 21 deletions base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -1094,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also deprecate this macro? (or remove if not used outside of base)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, chances are most of the Xmap_YZ macros/functions for SparseVectors can be cleaned out with some care :). Would a separate pull request be alright?

end


### Binary Map

# mode:
Expand Down
61 changes: 29 additions & 32 deletions test/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -656,42 +656,39 @@ 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

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


Expand Down