Skip to content

Commit cb674fa

Browse files
committed
Deprecate manually vectorized abs2 methods in favor of compact broadcast syntax.
1 parent 44d7677 commit cb674fa

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

base/deprecated.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,4 +1168,7 @@ for (dep, f, op) in [(:sumabs!, :sum!, :abs),
11681168
end
11691169
end
11701170

1171+
# Deprecate manually vectorized abs2 methods in favor of compact broadcast syntax
1172+
@deprecate abs2(x::AbstractSparseVector) abs2.(x)
1173+
11711174
# End deprecations scheduled for 0.6

base/sparse/sparsevector.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,8 @@ hvcat{T}(rows::Tuple{Vararg{Int}}, xs::_TypedDenseConcatGroup{T}...) = Base.type
919919

920920
# zero-preserving functions (z->z, nz->nz)
921921
broadcast(::typeof(abs), x::AbstractSparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), abs.(nonzeros(x)))
922-
for op in [:abs2, :conj]
922+
broadcast(::typeof(abs2), x::AbstractSparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), abs2.(nonzeros(x)))
923+
for op in [:conj]
923924
@eval begin
924925
$(op)(x::AbstractSparseVector) =
925926
SparseVector(length(x), copy(nonzeroinds(x)), $(op).(nonzeros(x)))

test/sparse/sparsevector.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ let x = spv_x1, x2 = x2 = spv_x2
588588

589589
# abs and abs2
590590
@test exact_equal(abs.(x), SparseVector(8, [2, 5, 6], abs.([1.25, -0.75, 3.5])))
591-
@test exact_equal(abs2(x), SparseVector(8, [2, 5, 6], abs2.([1.25, -0.75, 3.5])))
591+
@test exact_equal(abs2.(x), SparseVector(8, [2, 5, 6], abs2.([1.25, -0.75, 3.5])))
592592

593593
# plus and minus
594594
xa = SparseVector(8, [1,2,5,6,7], [3.25,5.25,-0.75,-2.0,-6.0])
@@ -610,7 +610,7 @@ let x = spv_x1, x2 = x2 = spv_x2
610610
# multiplies
611611
xm = SparseVector(8, [2, 6], [5.0, -19.25])
612612
let y=x # workaround for broadcast not preserving sparsity in general
613-
@test exact_equal(x .* y, abs2(x))
613+
@test exact_equal(x .* y, abs2.(x))
614614
end
615615
@test exact_equal(x .* x2, xm)
616616
@test exact_equal(x2 .* x, xm)

0 commit comments

Comments
 (0)