Skip to content

Commit 867ef9b

Browse files
committed
Deprecate manually vectorized ceil methods in favor of compact broadcast syntax.
1 parent 44d7677 commit 867ef9b

File tree

8 files changed

+41
-19
lines changed

8 files changed

+41
-19
lines changed

base/deprecated.jl

Lines changed: 7 additions & 0 deletions
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 ceil methods in favor of compact broadcast syntax
1172+
@deprecate ceil(M::Bidiagonal) ceil.(M)
1173+
@deprecate ceil(M::Tridiagonal) ceil.(M)
1174+
@deprecate ceil(M::SymTridiagonal) ceil.(M)
1175+
@deprecate ceil{T<:Integer}(::Type{T}, x::AbstractArray) ceil.(T, x)
1176+
@deprecate ceil(x::AbstractArray, digits::Integer, base::Integer = 10) ceil.(x, digits, base)
1177+
11711178
# End deprecations scheduled for 0.6

base/floatfuncs.jl

Lines changed: 1 addition & 1 deletion
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 (:trunc,:floor,: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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,12 @@ 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(ceil), M::Bidiagonal) = Bidiagonal(ceil.(M.dv), ceil.(M.ev), M.isupper)
257+
for func in (:conj, :copy, :round, :trunc, :floor, :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(ceil), ::Type{T}, M::Bidiagonal) = Bidiagonal(ceil.(T, M.dv), ceil.(T, M.ev), M.isupper)
261+
for func in (:round, :trunc, :floor)
260262
@eval ($func){T<:Integer}(::Type{T}, M::Bidiagonal) = Bidiagonal(($func)(T,M.dv), ($func)(T,M.ev), M.isupper)
261263
end
262264

base/linalg/tridiag.jl

Lines changed: 9 additions & 4 deletions
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(ceil), M::SymTridiagonal) = SymTridiagonal(ceil.(M.dv), ceil.(M.ev))
101+
for func in (:conj, :copy, :round, :trunc, :floor, :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(ceil), ::Type{T}, M::SymTridiagonal) = SymTridiagonal(ceil.(T, M.dv), ceil.(T, M.ev))
105+
for func in (:round, :trunc, :floor)
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(ceil), M::Tridiagonal) = Tridiagonal(ceil.(M.dl), ceil.(M.d), ceil.(M.du), ceil.(M.du2))
470+
for func in (:conj, :copy, :round, :trunc, :floor, :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(ceil), ::Type{T}, M::Tridiagonal) =
476+
Tridiagonal(ceil.(T, M.dl), ceil.(T, M.d), ceil.(T, M.du), ceil.(T, M.du2))
477+
for func in (:round, :trunc, :floor)
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

test/linalg/bidiag.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ srand(1)
166166
@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)
169-
@test ceil(Int,T) == Bidiagonal(ceil(Int,T.dv),ceil(Int,T.ev),T.isupper)
170-
@test isa(ceil(Int,T), Bidiagonal)
169+
@test ceil.(Int,T) == Bidiagonal(ceil.(Int,T.dv), ceil.(Int,T.ev), T.isupper)
170+
@test isa(ceil.(Int,T), Bidiagonal)
171171
end
172172
end
173173

test/linalg/tridiag.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ let n = 12 #Size of matrix problem to test
276276
@test isa(round(Int,A), SymTridiagonal)
277277
@test trunc(Int,A) == trunc(Int,fA)
278278
@test isa(trunc(Int,A), SymTridiagonal)
279-
@test ceil(Int,A) == ceil(Int,fA)
280-
@test isa(ceil(Int,A), SymTridiagonal)
279+
@test ceil.(Int,A) == ceil.(Int,fA)
280+
@test isa(ceil.(Int,A), SymTridiagonal)
281281
@test floor(Int,A) == floor(Int,fA)
282282
@test isa(floor(Int,A), SymTridiagonal)
283283
end
@@ -394,8 +394,8 @@ let n = 12 #Size of matrix problem to test
394394
@test isa(round(Int,A), Tridiagonal)
395395
@test trunc(Int,A) == trunc(Int,fA)
396396
@test isa(trunc(Int,A), Tridiagonal)
397-
@test ceil(Int,A) == ceil(Int,fA)
398-
@test isa(ceil(Int,A), Tridiagonal)
397+
@test ceil.(Int,A) == ceil.(Int,fA)
398+
@test isa(ceil.(Int,A), Tridiagonal)
399399
@test floor(Int,A) == floor(Int,fA)
400400
@test isa(floor(Int,A), Tridiagonal)
401401
end

test/numbers.jl

Lines changed: 10 additions & 2 deletions
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 (trunc, round, floor)
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 (ceil,)
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.)

test/sparse/sparse.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ end
499499
# Test representatives of [unary functions that map both zeros and nonzeros to nonzeros]
500500
@test cos.(Afull) == Array(cos.(A))
501501
# Test representatives of remaining vectorized-nonbroadcast unary functions
502-
@test ceil(Int, Afull) == Array(ceil(Int, A))
502+
@test ceil.(Int, Afull) == Array(ceil.(Int, A))
503503
@test floor(Int, Afull) == Array(floor(Int, A))
504504
# Tests of real, imag, abs, and abs2 for SparseMatrixCSC{Int,X}s previously elsewhere
505505
for T in (Int, Float16, Float32, Float64, BigInt, BigFloat)
@@ -1437,7 +1437,7 @@ end
14371437
# test sparse matrix norms
14381438
Ac = sprandn(10,10,.1) + im* sprandn(10,10,.1)
14391439
Ar = sprandn(10,10,.1)
1440-
Ai = ceil(Int,Ar*100)
1440+
Ai = ceil.(Int,Ar*100)
14411441
@test norm(Ac,1) norm(Array(Ac),1)
14421442
@test norm(Ac,Inf) norm(Array(Ac),Inf)
14431443
@test vecnorm(Ac) vecnorm(Array(Ac))
@@ -1478,9 +1478,9 @@ end
14781478

14791479
# test sparse matrix normestinv
14801480
Ac = sprandn(20,20,.5) + im* sprandn(20,20,.5)
1481-
Aci = ceil(Int64,100*sprand(20,20,.5))+ im*ceil(Int64,sprand(20,20,.5))
1481+
Aci = ceil.(Int64,100*sprand(20,20,.5))+ im*ceil.(Int64,sprand(20,20,.5))
14821482
Ar = sprandn(20,20,.5)
1483-
Ari = ceil(Int64,100*Ar)
1483+
Ari = ceil.(Int64,100*Ar)
14841484
if Base.USE_GPL_LIBS
14851485
@test_approx_eq_eps Base.SparseArrays.normestinv(Ac,3) norm(inv(Array(Ac)),1) 1e-4
14861486
@test_approx_eq_eps Base.SparseArrays.normestinv(Aci,3) norm(inv(Array(Aci)),1) 1e-4

0 commit comments

Comments
 (0)