Skip to content

Commit bcf16ac

Browse files
committed
Deprecate manually vectorized round methods in favor of compact broadcast syntax.
1 parent 9b414f2 commit bcf16ac

File tree

13 files changed

+64
-61
lines changed

13 files changed

+64
-61
lines changed

base/deprecated.jl

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

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

base/dsp.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function conv{T<:Base.LinAlg.BlasFloat}(u::StridedVector{T}, v::StridedVector{T}
141141
end
142142
return y[1:n]
143143
end
144-
conv{T<:Integer}(u::StridedVector{T}, v::StridedVector{T}) = round(Int,conv(float(u), float(v)))
144+
conv{T<:Integer}(u::StridedVector{T}, v::StridedVector{T}) = round.(Int,conv(float(u), float(v)))
145145
conv{T<:Integer, S<:Base.LinAlg.BlasFloat}(u::StridedVector{T}, v::StridedVector{S}) = conv(float(u), v)
146146
conv{T<:Integer, S<:Base.LinAlg.BlasFloat}(u::StridedVector{S}, v::StridedVector{T}) = conv(u, float(v))
147147

@@ -184,8 +184,8 @@ function conv2{T}(A::StridedMatrix{T}, B::StridedMatrix{T})
184184
end
185185
return C
186186
end
187-
conv2{T<:Integer}(A::StridedMatrix{T}, B::StridedMatrix{T}) = round(Int,conv2(float(A), float(B)))
188-
conv2{T<:Integer}(u::StridedVector{T}, v::StridedVector{T}, A::StridedMatrix{T}) = round(Int,conv2(float(u), float(v), float(A)))
187+
conv2{T<:Integer}(A::StridedMatrix{T}, B::StridedMatrix{T}) = round.(Int,conv2(float(A), float(B)))
188+
conv2{T<:Integer}(u::StridedVector{T}, v::StridedVector{T}, A::StridedMatrix{T}) = round.(Int,conv2(float(u), float(v), float(A)))
189189

190190
"""
191191
xcorr(u,v)

base/floatfuncs.jl

Lines changed: 1 addition & 21 deletions
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,:ceil)
116116
@eval begin
117117
function ($f){T,R}(::Type{T}, x::AbstractArray{R,1})
118118
[ ($f)(T, y)::T for y in x ]
@@ -135,26 +135,6 @@ for f in (:trunc,:floor,:ceil,:round)
135135
end
136136
end
137137

138-
function round{R}(x::AbstractArray{R,1}, r::RoundingMode)
139-
[ round(y, r) for y in x ]
140-
end
141-
function round{R}(x::AbstractArray{R,2}, r::RoundingMode)
142-
[ round(x[i,j], r) for i = 1:size(x,1), j = 1:size(x,2) ]
143-
end
144-
function round(x::AbstractArray, r::RoundingMode)
145-
reshape([ round(y, r) for y in x ], size(x))
146-
end
147-
148-
function round{T,R}(::Type{T}, x::AbstractArray{R,1}, r::RoundingMode)
149-
[ round(T, y, r)::T for y in x ]
150-
end
151-
function round{T,R}(::Type{T}, x::AbstractArray{R,2}, r::RoundingMode)
152-
[ round(T, x[i,j], r)::T for i = 1:size(x,1), j = 1:size(x,2) ]
153-
end
154-
function round{T}(::Type{T}, x::AbstractArray, r::RoundingMode)
155-
reshape([ round(T, y, r)::T for y in x ], size(x))
156-
end
157-
158138
# adapted from Matlab File Exchange roundsd: http://www.mathworks.com/matlabcentral/fileexchange/26212
159139
# for round, og is the power of 10 relative to the decimal point
160140
# for signif, og is the absolute power of 10

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(round), M::Bidiagonal) = Bidiagonal(round.(M.dv), round.(M.ev), M.isupper)
257+
for func in (:conj, :copy, :trunc, :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(round), ::Type{T}, M::Bidiagonal) = Bidiagonal(round.(T, M.dv), round.(T, M.ev), M.isupper)
261+
for func in (:trunc, :floor, :ceil)
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(round), M::SymTridiagonal) = SymTridiagonal(round.(M.dv), round.(M.ev))
101+
for func in (:conj, :copy, :trunc, :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(round), ::Type{T}, M::SymTridiagonal) = SymTridiagonal(round.(T, M.dv), round.(T, M.ev))
105+
for func in ( :trunc, :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(round), M::Tridiagonal) = Tridiagonal(round.(M.dl), round.(M.d), round.(M.du), round.(M.du2))
470+
for func in (:conj, :copy, :trunc, :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(round), ::Type{T}, M::Tridiagonal) =
476+
Tridiagonal(round.(T, M.dl), round.(T, M.d), round.(T, M.du), round.(T, M.du2))
477+
for func in (:trunc, :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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,6 @@ conj!(A::SparseMatrixCSC) = (broadcast!(conj, A.nzval, A.nzval); A)
22792279
ceil{To}(::Type{To}, A::SparseMatrixCSC) = ceil.(To, A)
22802280
floor{To}(::Type{To}, A::SparseMatrixCSC) = floor.(To, A)
22812281
trunc{To}(::Type{To}, A::SparseMatrixCSC) = trunc.(To, A)
2282-
round{To}(::Type{To}, A::SparseMatrixCSC) = round.(To, A)
22832282

22842283

22852284
## Binary arithmetic and boolean operators

examples/lru_test.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ get_str(i) = String(vcat(map(x->[x>>4; x&0x0F], reinterpret(UInt8, [Int32(i)])).
1010
isbounded{L<:LRUExample.LRU}(::Type{L}) = any(map(n->n==:maxsize, fieldnames(L)))
1111
isbounded{L<:LRUExample.LRU}(l::L) = isbounded(L)
1212

13-
nmax = round(Int,logspace(2, 5, 4))
13+
nmax = round.(Int, logspace(2, 5, 4))
1414

1515
function lrutest()
1616
#println("LRU consistency tests")

test/floatfuncs.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,26 @@ end
4545
for elty in (Float32,Float64)
4646
x = rand(elty)
4747
A = fill(x,(10,10))
48-
@test round(A,RoundToZero) == fill(trunc(x),(10,10))
49-
@test round(A,RoundUp) == fill(ceil(x),(10,10))
50-
@test round(A,RoundDown) == fill(floor(x),(10,10))
48+
@test round.(A,RoundToZero) == fill(trunc(x),(10,10))
49+
@test round.(A,RoundUp) == fill(ceil(x),(10,10))
50+
@test round.(A,RoundDown) == fill(floor(x),(10,10))
5151
A = fill(x,(10,10,10))
52-
@test round(A,RoundToZero) == fill(trunc(x),(10,10,10))
53-
@test round(A,RoundUp) == fill(ceil(x),(10,10,10))
54-
@test round(A,RoundDown) == fill(floor(x),(10,10,10))
52+
@test round.(A,RoundToZero) == fill(trunc(x),(10,10,10))
53+
@test round.(A,RoundUp) == fill(ceil(x),(10,10,10))
54+
@test round.(A,RoundDown) == fill(floor(x),(10,10,10))
5555
for elty2 in (Int32,Int64)
5656
A = fill(x,(10,))
57-
@test round(elty2,A,RoundToZero) == fill(trunc(elty2,x),(10,))
58-
@test round(elty2,A,RoundUp) == fill(ceil(elty2,x),(10,))
59-
@test round(elty2,A,RoundDown) == fill(floor(elty2,x),(10,))
57+
@test round.(elty2,A,RoundToZero) == fill(trunc(elty2,x),(10,))
58+
@test round.(elty2,A,RoundUp) == fill(ceil(elty2,x),(10,))
59+
@test round.(elty2,A,RoundDown) == fill(floor(elty2,x),(10,))
6060
A = fill(x,(10,10))
61-
@test round(elty2,A,RoundToZero) == fill(trunc(elty2,x),(10,10))
62-
@test round(elty2,A,RoundUp) == fill(ceil(elty2,x),(10,10))
63-
@test round(elty2,A,RoundDown) == fill(floor(elty2,x),(10,10))
61+
@test round.(elty2,A,RoundToZero) == fill(trunc(elty2,x),(10,10))
62+
@test round.(elty2,A,RoundUp) == fill(ceil(elty2,x),(10,10))
63+
@test round.(elty2,A,RoundDown) == fill(floor(elty2,x),(10,10))
6464
A = fill(x,(10,10,10))
65-
@test round(elty2,A,RoundToZero) == fill(trunc(elty2,x),(10,10,10))
66-
@test round(elty2,A,RoundUp) == fill(ceil(elty2,x),(10,10,10))
67-
@test round(elty2,A,RoundDown) == fill(floor(elty2,x),(10,10,10))
68-
@test round(elty2,A) == fill(round(elty2,x),(10,10,10))
65+
@test round.(elty2,A,RoundToZero) == fill(trunc(elty2,x),(10,10,10))
66+
@test round.(elty2,A,RoundUp) == fill(ceil(elty2,x),(10,10,10))
67+
@test round.(elty2,A,RoundDown) == fill(floor(elty2,x),(10,10,10))
68+
@test round.(elty2,A) == fill(round(elty2,x),(10,10,10))
6969
end
7070
end

test/linalg/bidiag.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ srand(1)
164164
@test isa(floor(Int,T), Bidiagonal)
165165
@test trunc(Int,T) == Bidiagonal(trunc(Int,T.dv),trunc(Int,T.ev),T.isupper)
166166
@test isa(trunc(Int,T), Bidiagonal)
167-
@test round(Int,T) == Bidiagonal(round(Int,T.dv),round(Int,T.ev),T.isupper)
168-
@test isa(round(Int,T), Bidiagonal)
167+
@test round.(Int, T) == Bidiagonal(round.(Int, T.dv), round.(Int, T.ev), T.isupper)
168+
@test isa(round.(Int, T), Bidiagonal)
169169
@test ceil(Int,T) == Bidiagonal(ceil(Int,T.dv),ceil(Int,T.ev),T.isupper)
170170
@test isa(ceil(Int,T), Bidiagonal)
171171
end

test/linalg/tridiag.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ let n = 12 #Size of matrix problem to test
272272

273273
debug && println("Rounding to Ints")
274274
if elty <: Real
275-
@test round(Int,A) == round(Int,fA)
276-
@test isa(round(Int,A), SymTridiagonal)
275+
@test round.(Int,A) == round.(Int,fA)
276+
@test isa(round.(Int,A), SymTridiagonal)
277277
@test trunc(Int,A) == trunc(Int,fA)
278278
@test isa(trunc(Int,A), SymTridiagonal)
279279
@test ceil(Int,A) == ceil(Int,fA)
@@ -390,8 +390,8 @@ let n = 12 #Size of matrix problem to test
390390

391391
debug && println("Rounding to Ints")
392392
if elty <: Real
393-
@test round(Int,A) == round(Int,fA)
394-
@test isa(round(Int,A), Tridiagonal)
393+
@test round.(Int,A) == round.(Int,fA)
394+
@test isa(round.(Int,A), Tridiagonal)
395395
@test trunc(Int,A) == trunc(Int,fA)
396396
@test isa(trunc(Int,A), Tridiagonal)
397397
@test ceil(Int,A) == ceil(Int,fA)

0 commit comments

Comments
 (0)