Skip to content

Commit

Permalink
Deprecate manually vectorized abs2 methods in favor of compact broadc…
Browse files Browse the repository at this point in the history
…ast syntax.
  • Loading branch information
Sacha0 committed Sep 17, 2016
1 parent 3a31155 commit 4fc0d67
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1000,4 +1000,7 @@ macro vectorize_2arg(S,f)
end
export @vectorize_1arg, @vectorize_2arg

# Deprecate manually vectorized abs2 methods in favor of compact broadcast syntax
@deprecate abs2(x::AbstractSparseVector) abs2.(x)

# End deprecations scheduled for 0.6
5 changes: 3 additions & 2 deletions base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license
9# This file is a part of Julia. License is MIT: http://julialang.org/license

### Common definitions

Expand Down Expand Up @@ -912,7 +912,8 @@ hvcat{T}(rows::Tuple{Vararg{Int}}, xs::_TypedDenseConcatGroup{T}...) = Base.type
### Unary Map

# zero-preserving functions (z->z, nz->nz)
for op in [:abs, :abs2, :conj]
broadcast(::typeof(abs2), x::AbstractSparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), abs2.(nonzeros(x)))
for op in [:abs, :conj]
@eval begin
$(op)(x::AbstractSparseVector) =
SparseVector(length(x), copy(nonzeroinds(x)), $(op).(nonzeros(x)))
Expand Down
4 changes: 2 additions & 2 deletions test/sparsedir/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ let x = spv_x1, x2 = 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 @@ -581,7 +581,7 @@ let x = spv_x1, x2 = x2 = spv_x2

# multiplies
xm = SparseVector(8, [2, 6], [5.0, -19.25])
@test exact_equal(x .* x, abs2(x))
@test exact_equal(x .* x, abs2.(x))
@test exact_equal(x .* x2, xm)
@test exact_equal(x2 .* x, xm)

Expand Down

0 comments on commit 4fc0d67

Please sign in to comment.