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

Deprecate vectorized abs2 methods in favor of compact broadcast syntax #18564

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Contributor

Choose a reason for hiding this comment

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

will conj be implemented as a method of broadcast once that supports sparse vectors?

Copy link
Member Author

Choose a reason for hiding this comment

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

IIUC conj methods for vectors/matrices should persist per discussion in #18495 (comment). Thoughts? Thanks!

Copy link
Contributor

@tkelman tkelman Dec 30, 2016

Choose a reason for hiding this comment

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

right the method will stay without dots, I'm asking if this implementation will remain. not really a feature freeze issue, but possible cleanup for later

Copy link
Member Author

Choose a reason for hiding this comment

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

Cheers, with you now. Definitely a candidate for cleanup, and likewise for several more methods in base/sparse/sparsevectors.jl. Best!

@eval begin
$(op)(x::AbstractSparseVector) =
SparseVector(length(x), copy(nonzeroinds(x)), $(op).(nonzeros(x)))
Expand Down
4 changes: 2 additions & 2 deletions test/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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)
Expand Down