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

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
7 changes: 7 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1168,4 +1168,11 @@ for (dep, f, op) in [(:sumabs!, :sum!, :abs),
end
end

# Deprecate manually vectorized trunc methods in favor of compact broadcast syntax
@deprecate trunc(M::Bidiagonal) trunc.(M)
@deprecate trunc(M::Tridiagonal) trunc.(M)
@deprecate trunc(M::SymTridiagonal) trunc.(M)
@deprecate trunc{T<:Integer}(::Type{T}, x::AbstractArray) trunc.(T, x)
@deprecate trunc(x::AbstractArray, digits::Integer, base::Integer = 10) trunc.(x, digits, base)

# End deprecations scheduled for 0.6
2 changes: 1 addition & 1 deletion base/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function round(x::AbstractFloat, ::RoundingMode{:NearestTiesUp})
end
round{T<:Integer}(::Type{T}, x::AbstractFloat, r::RoundingMode) = trunc(T,round(x,r))

for f in (:trunc,:floor,:ceil,:round)
for f in (:floor,:ceil,:round)
@eval begin
function ($f){T,R}(::Type{T}, x::AbstractArray{R,1})
[ ($f)(T, y)::T for y in x ]
Expand Down
7 changes: 5 additions & 2 deletions base/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,13 @@ end

#Elementary operations
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)
broadcast(::typeof(trunc), M::Bidiagonal) = Bidiagonal(trunc.(M.dv), trunc.(M.ev), M.isupper)
for func in (:conj, :copy, :round, :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)
broadcast{T<:Integer}(::typeof(trunc), ::Type{T}, M::Bidiagonal) =
Bidiagonal(trunc.(T, M.dv), trunc.(T, M.ev), M.isupper)
for func in (:round, :floor, :ceil)
@eval ($func){T<:Integer}(::Type{T}, M::Bidiagonal) = Bidiagonal(($func)(T,M.dv), ($func)(T,M.ev), M.isupper)
end

Expand Down
13 changes: 9 additions & 4 deletions base/linalg/tridiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ similar{T}(S::SymTridiagonal, ::Type{T}) = SymTridiagonal{T}(similar(S.dv, T), s

#Elementary operations
broadcast(::typeof(abs), M::SymTridiagonal) = SymTridiagonal(abs.(M.dv), abs.(M.ev))
for func in (:conj, :copy, :round, :trunc, :floor, :ceil, :real, :imag)
broadcast(::typeof(trunc), M::SymTridiagonal) = SymTridiagonal(trunc.(M.dv), trunc.(M.ev))
for func in (:conj, :copy, :round, :floor, :ceil, :real, :imag)
@eval ($func)(M::SymTridiagonal) = SymTridiagonal(($func)(M.dv), ($func)(M.ev))
end
for func in (:round, :trunc, :floor, :ceil)
broadcast{T<:Integer}(::typeof(trunc), ::Type{T}, M::SymTridiagonal) = SymTridiagonal(trunc.(T, M.dv), trunc.(T, M.ev))
for func in (:round, :floor, :ceil)
@eval ($func){T<:Integer}(::Type{T},M::SymTridiagonal) = SymTridiagonal(($func)(T,M.dv), ($func)(T,M.ev))
end
transpose(M::SymTridiagonal) = M #Identity operation
Expand Down Expand Up @@ -464,12 +466,15 @@ copy!(dest::Tridiagonal, src::Tridiagonal) = Tridiagonal(copy!(dest.dl, src.dl),

#Elementary operations
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)
broadcast(::typeof(trunc), M::Tridiagonal) = Tridiagonal(trunc.(M.dl), trunc.(M.d), trunc.(M.du), trunc.(M.du2))
for func in (:conj, :copy, :round, :floor, :ceil, :real, :imag)
@eval function ($func)(M::Tridiagonal)
Tridiagonal(($func)(M.dl), ($func)(M.d), ($func)(M.du), ($func)(M.du2))
end
end
for func in (:round, :trunc, :floor, :ceil)
broadcast{T<:Integer}(::typeof(trunc), ::Type{T}, M::Tridiagonal) =
Tridiagonal(trunc.(T, M.dl), trunc.(T, M.d), trunc.(T, M.du), trunc.(T, M.du2))
for func in (:round, :floor, :ceil)
@eval function ($func){T<:Integer}(::Type{T},M::Tridiagonal)
Tridiagonal(($func)(T,M.dl), ($func)(T,M.d), ($func)(T,M.du), ($func)(T,M.du2))
end
Expand Down
1 change: 0 additions & 1 deletion base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2278,7 +2278,6 @@ conj!(A::SparseMatrixCSC) = (broadcast!(conj, A.nzval, A.nzval); A)
# TODO: The following definitions should be deprecated.
ceil{To}(::Type{To}, A::SparseMatrixCSC) = ceil.(To, A)
floor{To}(::Type{To}, A::SparseMatrixCSC) = floor.(To, A)
trunc{To}(::Type{To}, A::SparseMatrixCSC) = trunc.(To, A)
round{To}(::Type{To}, A::SparseMatrixCSC) = round.(To, A)


Expand Down
4 changes: 2 additions & 2 deletions test/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ srand(1)
if elty <: BlasReal
@test floor(Int,T) == Bidiagonal(floor(Int,T.dv),floor(Int,T.ev),T.isupper)
@test isa(floor(Int,T), Bidiagonal)
@test trunc(Int,T) == Bidiagonal(trunc(Int,T.dv),trunc(Int,T.ev),T.isupper)
@test isa(trunc(Int,T), Bidiagonal)
@test trunc.(Int,T) == Bidiagonal(trunc.(Int, T.dv), trunc.(Int, T.ev), T.isupper)
@test isa(trunc.(Int,T), Bidiagonal)
@test round(Int,T) == Bidiagonal(round(Int,T.dv),round(Int,T.ev),T.isupper)
@test isa(round(Int,T), Bidiagonal)
@test ceil(Int,T) == Bidiagonal(ceil(Int,T.dv),ceil(Int,T.ev),T.isupper)
Expand Down
2 changes: 1 addition & 1 deletion test/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
end

debug && println("Test forward error [JIN 5705] if this is not a BigFloat")
b = eltyb == Int ? trunc(Int,Atri*ones(n, 2)) : convert(Matrix{eltyb}, Atri*ones(eltya, n, 2))
b = eltyb == Int ? trunc.(Int,Atri*ones(n, 2)) : convert(Matrix{eltyb}, Atri*ones(eltya, n, 2))
x = Atri \ b
γ = n*ε/(1 - n*ε)
if eltya != BigFloat
Expand Down
8 changes: 4 additions & 4 deletions test/linalg/tridiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ let n = 12 #Size of matrix problem to test
if elty <: Real
@test round(Int,A) == round(Int,fA)
@test isa(round(Int,A), SymTridiagonal)
@test trunc(Int,A) == trunc(Int,fA)
@test isa(trunc(Int,A), SymTridiagonal)
@test trunc.(Int,A) == trunc.(Int,fA)
@test isa(trunc.(Int,A), SymTridiagonal)
@test ceil(Int,A) == ceil(Int,fA)
@test isa(ceil(Int,A), SymTridiagonal)
@test floor(Int,A) == floor(Int,fA)
Expand Down Expand Up @@ -392,8 +392,8 @@ let n = 12 #Size of matrix problem to test
if elty <: Real
@test round(Int,A) == round(Int,fA)
@test isa(round(Int,A), Tridiagonal)
@test trunc(Int,A) == trunc(Int,fA)
@test isa(trunc(Int,A), Tridiagonal)
@test trunc.(Int,A) == trunc.(Int,fA)
@test isa(trunc.(Int,A), Tridiagonal)
@test ceil(Int,A) == ceil(Int,fA)
@test isa(ceil(Int,A), Tridiagonal)
@test floor(Int,A) == floor(Int,fA)
Expand Down
12 changes: 10 additions & 2 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2026,14 +2026,22 @@ x = 0.0
@test approx_eq(round(pi,3,5), 3.144)
# vectorized trunc/round/floor/ceil with digits/base argument
a = rand(2, 2, 2)
for f in (trunc, round, floor, ceil)
for f in (round, floor, ceil)
@test f(a[:, 1, 1], 2) == map(x->f(x, 2), a[:, 1, 1])
@test f(a[:, :, 1], 2) == map(x->f(x, 2), a[:, :, 1])
@test f(a, 9, 2) == map(x->f(x, 9, 2), a)
@test f(a[:, 1, 1], 9, 2) == map(x->f(x, 9, 2), a[:, 1, 1])
@test f(a[:, :, 1], 9, 2) == map(x->f(x, 9, 2), a[:, :, 1])
@test f(a, 9, 2) == map(x->f(x, 9, 2), a)
end
end
for f in (trunc,)
@test f.(a[:, 1, 1], 2) == map(x->f(x, 2), a[:, 1, 1])
@test f.(a[:, :, 1], 2) == map(x->f(x, 2), a[:, :, 1])
@test f.(a, 9, 2) == map(x->f(x, 9, 2), a)
@test f.(a[:, 1, 1], 9, 2) == map(x->f(x, 9, 2), a[:, 1, 1])
@test f.(a[:, :, 1], 9, 2) == map(x->f(x, 9, 2), a[:, :, 1])
@test f.(a, 9, 2) == map(x->f(x, 9, 2), a)
end
# significant digits (would be nice to have a smart vectorized
# version of signif)
@test approx_eq(signif(123.456,1), 100.)
Expand Down
2 changes: 1 addition & 1 deletion test/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ end
@test norm(Ai,1) ≈ norm(Array(Ai),1)
@test norm(Ai,Inf) ≈ norm(Array(Ai),Inf)
@test vecnorm(Ai) ≈ vecnorm(Array(Ai))
Ai = trunc(Int,Ar*100)
Ai = trunc.(Int, Ar*100)
@test norm(Ai,1) ≈ norm(Array(Ai),1)
@test norm(Ai,Inf) ≈ norm(Array(Ai),Inf)
@test vecnorm(Ai) ≈ vecnorm(Array(Ai))
Expand Down