Skip to content

Commit 0d92276

Browse files
committed
Deprecate manually vectorized trunc methods in favor of compact broadcast syntax.
1 parent 44d7677 commit 0d92276

File tree

9 files changed

+39
-17
lines changed

9 files changed

+39
-17
lines changed

base/deprecated.jl

+7
Original file line numberDiff line numberDiff line change
@@ -1168,4 +1168,11 @@ for (dep, f, op) in [(:sumabs!, :sum!, :abs),
11681168
end
11691169
end
11701170

1171+
# Deprecate manually vectorized trunc methods in favor of compact broadcast syntax
1172+
@deprecate trunc(M::Bidiagonal) trunc.(M)
1173+
@deprecate trunc(M::Tridiagonal) trunc.(M)
1174+
@deprecate trunc(M::SymTridiagonal) trunc.(M)
1175+
@deprecate trunc{T<:Integer}(::Type{T}, x::AbstractArray) trunc.(T, x)
1176+
@deprecate trunc(x::AbstractArray, digits::Integer, base::Integer = 10) trunc.(x, digits, base)
1177+
11711178
# End deprecations scheduled for 0.6

base/floatfuncs.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function round(x::AbstractFloat, ::RoundingMode{:NearestTiesUp})
112112
end
113113
round{T<:Integer}(::Type{T}, x::AbstractFloat, r::RoundingMode) = trunc(T,round(x,r))
114114

115-
for f in (:trunc,:floor,:ceil,:round)
115+
for f in (:floor,:ceil,:round)
116116
@eval begin
117117
function ($f){T,R}(::Type{T}, x::AbstractArray{R,1})
118118
[ ($f)(T, y)::T for y in x ]

base/linalg/bidiag.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,13 @@ end
253253

254254
#Elementary operations
255255
broadcast(::typeof(abs), M::Bidiagonal) = Bidiagonal(abs.(M.dv), abs.(M.ev), abs.(M.isupper))
256-
for func in (:conj, :copy, :round, :trunc, :floor, :ceil, :real, :imag)
256+
broadcast(::typeof(trunc), M::Bidiagonal) = Bidiagonal(trunc.(M.dv), trunc.(M.ev), M.isupper)
257+
for func in (:conj, :copy, :round, :floor, :ceil, :real, :imag)
257258
@eval ($func)(M::Bidiagonal) = Bidiagonal(($func)(M.dv), ($func)(M.ev), M.isupper)
258259
end
259-
for func in (:round, :trunc, :floor, :ceil)
260+
broadcast{T<:Integer}(::typeof(trunc), ::Type{T}, M::Bidiagonal) =
261+
Bidiagonal(trunc.(T, M.dv), trunc.(T, M.ev), M.isupper)
262+
for func in (:round, :floor, :ceil)
260263
@eval ($func){T<:Integer}(::Type{T}, M::Bidiagonal) = Bidiagonal(($func)(T,M.dv), ($func)(T,M.ev), M.isupper)
261264
end
262265

base/linalg/tridiag.jl

+9-4
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ similar{T}(S::SymTridiagonal, ::Type{T}) = SymTridiagonal{T}(similar(S.dv, T), s
9797

9898
#Elementary operations
9999
broadcast(::typeof(abs), M::SymTridiagonal) = SymTridiagonal(abs.(M.dv), abs.(M.ev))
100-
for func in (:conj, :copy, :round, :trunc, :floor, :ceil, :real, :imag)
100+
broadcast(::typeof(trunc), M::SymTridiagonal) = SymTridiagonal(trunc.(M.dv), trunc.(M.ev))
101+
for func in (:conj, :copy, :round, :floor, :ceil, :real, :imag)
101102
@eval ($func)(M::SymTridiagonal) = SymTridiagonal(($func)(M.dv), ($func)(M.ev))
102103
end
103-
for func in (:round, :trunc, :floor, :ceil)
104+
broadcast{T<:Integer}(::typeof(trunc), ::Type{T}, M::SymTridiagonal) = SymTridiagonal(trunc.(T, M.dv), trunc.(T, M.ev))
105+
for func in (:round, :floor, :ceil)
104106
@eval ($func){T<:Integer}(::Type{T},M::SymTridiagonal) = SymTridiagonal(($func)(T,M.dv), ($func)(T,M.ev))
105107
end
106108
transpose(M::SymTridiagonal) = M #Identity operation
@@ -464,12 +466,15 @@ copy!(dest::Tridiagonal, src::Tridiagonal) = Tridiagonal(copy!(dest.dl, src.dl),
464466

465467
#Elementary operations
466468
broadcast(::typeof(abs), M::Tridiagonal) = Tridiagonal(abs.(M.dl), abs.(M.d), abs.(M.du), abs.(M.du2))
467-
for func in (:conj, :copy, :round, :trunc, :floor, :ceil, :real, :imag)
469+
broadcast(::typeof(trunc), M::Tridiagonal) = Tridiagonal(trunc.(M.dl), trunc.(M.d), trunc.(M.du), trunc.(M.du2))
470+
for func in (:conj, :copy, :round, :floor, :ceil, :real, :imag)
468471
@eval function ($func)(M::Tridiagonal)
469472
Tridiagonal(($func)(M.dl), ($func)(M.d), ($func)(M.du), ($func)(M.du2))
470473
end
471474
end
472-
for func in (:round, :trunc, :floor, :ceil)
475+
broadcast{T<:Integer}(::typeof(trunc), ::Type{T}, M::Tridiagonal) =
476+
Tridiagonal(trunc.(T, M.dl), trunc.(T, M.d), trunc.(T, M.du), trunc.(T, M.du2))
477+
for func in (:round, :floor, :ceil)
473478
@eval function ($func){T<:Integer}(::Type{T},M::Tridiagonal)
474479
Tridiagonal(($func)(T,M.dl), ($func)(T,M.d), ($func)(T,M.du), ($func)(T,M.du2))
475480
end

base/sparse/sparsematrix.jl

-1
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,6 @@ conj!(A::SparseMatrixCSC) = (broadcast!(conj, A.nzval, A.nzval); A)
22782278
# TODO: The following definitions should be deprecated.
22792279
ceil{To}(::Type{To}, A::SparseMatrixCSC) = ceil.(To, A)
22802280
floor{To}(::Type{To}, A::SparseMatrixCSC) = floor.(To, A)
2281-
trunc{To}(::Type{To}, A::SparseMatrixCSC) = trunc.(To, A)
22822281
round{To}(::Type{To}, A::SparseMatrixCSC) = round.(To, A)
22832282

22842283

test/linalg/bidiag.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ srand(1)
162162
if elty <: BlasReal
163163
@test floor(Int,T) == Bidiagonal(floor(Int,T.dv),floor(Int,T.ev),T.isupper)
164164
@test isa(floor(Int,T), Bidiagonal)
165-
@test trunc(Int,T) == Bidiagonal(trunc(Int,T.dv),trunc(Int,T.ev),T.isupper)
166-
@test isa(trunc(Int,T), Bidiagonal)
165+
@test trunc.(Int,T) == Bidiagonal(trunc.(Int, T.dv), trunc.(Int, T.ev), T.isupper)
166+
@test isa(trunc.(Int,T), Bidiagonal)
167167
@test round(Int,T) == Bidiagonal(round(Int,T.dv),round(Int,T.ev),T.isupper)
168168
@test isa(round(Int,T), Bidiagonal)
169169
@test ceil(Int,T) == Bidiagonal(ceil(Int,T.dv),ceil(Int,T.ev),T.isupper)

test/linalg/triangular.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
442442
end
443443

444444
debug && println("Test forward error [JIN 5705] if this is not a BigFloat")
445-
b = eltyb == Int ? trunc(Int,Atri*ones(n, 2)) : convert(Matrix{eltyb}, Atri*ones(eltya, n, 2))
445+
b = eltyb == Int ? trunc.(Int,Atri*ones(n, 2)) : convert(Matrix{eltyb}, Atri*ones(eltya, n, 2))
446446
x = Atri \ b
447447
γ = n*ε/(1 - n*ε)
448448
if eltya != BigFloat

test/linalg/tridiag.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ let n = 12 #Size of matrix problem to test
274274
if elty <: Real
275275
@test round(Int,A) == round(Int,fA)
276276
@test isa(round(Int,A), SymTridiagonal)
277-
@test trunc(Int,A) == trunc(Int,fA)
278-
@test isa(trunc(Int,A), SymTridiagonal)
277+
@test trunc.(Int,A) == trunc.(Int,fA)
278+
@test isa(trunc.(Int,A), SymTridiagonal)
279279
@test ceil(Int,A) == ceil(Int,fA)
280280
@test isa(ceil(Int,A), SymTridiagonal)
281281
@test floor(Int,A) == floor(Int,fA)
@@ -392,8 +392,8 @@ let n = 12 #Size of matrix problem to test
392392
if elty <: Real
393393
@test round(Int,A) == round(Int,fA)
394394
@test isa(round(Int,A), Tridiagonal)
395-
@test trunc(Int,A) == trunc(Int,fA)
396-
@test isa(trunc(Int,A), Tridiagonal)
395+
@test trunc.(Int,A) == trunc.(Int,fA)
396+
@test isa(trunc.(Int,A), Tridiagonal)
397397
@test ceil(Int,A) == ceil(Int,fA)
398398
@test isa(ceil(Int,A), Tridiagonal)
399399
@test floor(Int,A) == floor(Int,fA)

test/numbers.jl

+10-2
Original file line numberDiff line numberDiff line change
@@ -2026,14 +2026,22 @@ x = 0.0
20262026
@test approx_eq(round(pi,3,5), 3.144)
20272027
# vectorized trunc/round/floor/ceil with digits/base argument
20282028
a = rand(2, 2, 2)
2029-
for f in (trunc, round, floor, ceil)
2029+
for f in (round, floor, ceil)
20302030
@test f(a[:, 1, 1], 2) == map(x->f(x, 2), a[:, 1, 1])
20312031
@test f(a[:, :, 1], 2) == map(x->f(x, 2), a[:, :, 1])
20322032
@test f(a, 9, 2) == map(x->f(x, 9, 2), a)
20332033
@test f(a[:, 1, 1], 9, 2) == map(x->f(x, 9, 2), a[:, 1, 1])
20342034
@test f(a[:, :, 1], 9, 2) == map(x->f(x, 9, 2), a[:, :, 1])
20352035
@test f(a, 9, 2) == map(x->f(x, 9, 2), a)
2036-
end
2036+
end
2037+
for f in (trunc,)
2038+
@test f.(a[:, 1, 1], 2) == map(x->f(x, 2), a[:, 1, 1])
2039+
@test f.(a[:, :, 1], 2) == map(x->f(x, 2), a[:, :, 1])
2040+
@test f.(a, 9, 2) == map(x->f(x, 9, 2), a)
2041+
@test f.(a[:, 1, 1], 9, 2) == map(x->f(x, 9, 2), a[:, 1, 1])
2042+
@test f.(a[:, :, 1], 9, 2) == map(x->f(x, 9, 2), a[:, :, 1])
2043+
@test f.(a, 9, 2) == map(x->f(x, 9, 2), a)
2044+
end
20372045
# significant digits (would be nice to have a smart vectorized
20382046
# version of signif)
20392047
@test approx_eq(signif(123.456,1), 100.)

0 commit comments

Comments
 (0)