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 abs methods in favor of compact broadcast syntax #18558

Merged
merged 1 commit into from
Sep 21, 2016
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
2 changes: 1 addition & 1 deletion base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ function empty!(B::BitVector)
end

## Misc functions
abs(B::BitArray) = copy(B)
broadcast(::typeof(abs), B::BitArray) = copy(B)

## Unary operators ##

Expand Down
3 changes: 2 additions & 1 deletion base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module Broadcast
using Base.Cartesian
using Base: promote_eltype_op, @get!, _msk_end, unsafe_bitgetindex, linearindices, tail, OneTo, to_shape
import Base: .+, .-, .*, ./, .\, .//, .==, .<, .!=, .<=, .÷, .%, .<<, .>>, .^
export broadcast, broadcast!, bitbroadcast, dotview
import Base: broadcast
export broadcast!, bitbroadcast, dotview
export broadcast_getindex, broadcast_setindex!

## Broadcasting utilities ##
Expand Down
9 changes: 9 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1000,4 +1000,13 @@ macro vectorize_2arg(S,f)
end
export @vectorize_1arg, @vectorize_2arg

# Devectorize manually vectorized abs methods in favor of compact broadcast syntax
@deprecate abs(f::Base.Pkg.Resolve.MaxSum.Field) abs.(f)
@deprecate abs(B::BitArray) abs.(B)
@deprecate abs(M::Bidiagonal) abs.(M)
@deprecate abs(D::Diagonal) abs.(D)
@deprecate abs(M::Tridiagonal) abs.(M)
@deprecate abs(M::SymTridiagonal) abs.(M)
@deprecate abs(x::AbstractSparseVector) abs.(x)

# End deprecations scheduled for 0.6
3 changes: 2 additions & 1 deletion base/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ function size(M::Bidiagonal, d::Integer)
end

#Elementary operations
for func in (:conj, :copy, :round, :trunc, :floor, :ceil, :real, :imag, :abs)
broadcast(::typeof(abs), M::Bidiagonal) = Bidiagonal(abs.(M.dv), abs.(M.ev), abs.(M.isupper))
for func in (:conj, :copy, :round, :trunc, :floor, :ceil, :real, :imag)
@eval ($func)(M::Bidiagonal) = Bidiagonal(($func)(M.dv), ($func)(M.ev), M.isupper)
end
for func in (:round, :trunc, :floor, :ceil)
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ isposdef(D::Diagonal) = all(D.diag .> 0)

factorize(D::Diagonal) = D

abs(D::Diagonal) = Diagonal(abs(D.diag))
broadcast(::typeof(abs), D::Diagonal) = Diagonal(abs.(D.diag))
real(D::Diagonal) = Diagonal(real(D.diag))
imag(D::Diagonal) = Diagonal(imag(D.diag))

Expand Down
6 changes: 4 additions & 2 deletions base/linalg/tridiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ end
similar{T}(S::SymTridiagonal, ::Type{T}) = SymTridiagonal{T}(similar(S.dv, T), similar(S.ev, T))

#Elementary operations
for func in (:conj, :copy, :round, :trunc, :floor, :ceil, :abs, :real, :imag)
broadcast(::typeof(abs), M::SymTridiagonal) = SymTridiagonal(abs.(M.dv), abs.(M.ev))
for func in (:conj, :copy, :round, :trunc, :floor, :ceil, :real, :imag)
@eval ($func)(M::SymTridiagonal) = SymTridiagonal(($func)(M.dv), ($func)(M.ev))
end
for func in (:round, :trunc, :floor, :ceil)
Expand Down Expand Up @@ -388,7 +389,8 @@ end
copy!(dest::Tridiagonal, src::Tridiagonal) = Tridiagonal(copy!(dest.dl, src.dl), copy!(dest.d, src.d), copy!(dest.du, src.du), copy!(dest.du2, src.du2))

#Elementary operations
for func in (:conj, :copy, :round, :trunc, :floor, :ceil, :abs, :real, :imag)
broadcast(::typeof(abs), M::Tridiagonal) = Tridiagonal(abs.(M.dl), abs.(M.d), abs.(M.du), abs.(M.du2))
for func in (:conj, :copy, :round, :trunc, :floor, :ceil, :real, :imag)
@eval function ($func)(M::Tridiagonal)
Tridiagonal(($func)(M.dl), ($func)(M.d), ($func)(M.du), ($func)(M.du2))
end
Expand Down
1 change: 0 additions & 1 deletion base/pkg/resolve/fieldvalue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ end
a.l0 == b.l0 && a.l1 == b.l1 && a.l2 == b.l2 && a.l3 == b.l3 && a.l4 == b.l4

Base.abs(a::FieldValue) = FieldValue(abs(a.l0), abs(a.l1), abs(a.l2), abs(a.l3), abs(a.l4))
Base.abs(f::Field) = FieldValue[abs(a) for a in f]

# if the maximum field has l0 < 0, it means that
# some hard constraint is being violated
Expand Down
2 changes: 1 addition & 1 deletion base/pkg/resolve/maxsum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function update(p0::Int, graph::Graph, msgs::Messages)
end

diff = newmsg - oldmsg
maxdiff = max(maxdiff, maximum(abs(diff)))
maxdiff = max(maxdiff, maximum(abs.(diff)))

# update the field of p1
fld1 = fld[p1]
Expand Down
3 changes: 2 additions & 1 deletion base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
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(abs), x::AbstractSparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), abs.(nonzeros(x)))
for op in [:abs2, :conj]
@eval begin
$(op)(x::AbstractSparseVector) =
SparseVector(length(x), copy(nonzeroinds(x)), $(op).(nonzeros(x)))
Expand Down
2 changes: 1 addition & 1 deletion test/perf/kernel/gk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function gk(n, myeps)

AX=A*X
Ax = A*x
error=abs(AX)-abs(U)
error=abs.(AX)-abs.(U)
#print(Ax)

Axepse=0
Expand Down
6 changes: 3 additions & 3 deletions test/sparsedir/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ let x = spv_x1, x2 = x2 = spv_x2
@test exact_equal(-x, SparseVector(8, [2, 5, 6], [-1.25, 0.75, -3.5]))

# abs and abs2
@test exact_equal(abs(x), SparseVector(8, [2, 5, 6], abs.([1.25, -0.75, 3.5])))
@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])))

# plus and minus
Expand Down Expand Up @@ -683,12 +683,12 @@ let x = spv_x1
@test minabs(x) == 0.0
end

let x = abs(spv_x1)
let x = abs.(spv_x1)
@test maximum(x) == 3.5
@test minimum(x) == 0.0
end

let x = -abs(spv_x1)
let x = -abs.(spv_x1)
@test maximum(x) == 0.0
@test minimum(x) == -3.5
end
Expand Down