Skip to content
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 floor methods in favor of compact broadcast syntax
@deprecate floor(M::Bidiagonal) floor.(M)
@deprecate floor(M::Tridiagonal) floor.(M)
@deprecate floor(M::SymTridiagonal) floor.(M)
@deprecate floor{T<:Integer}(::Type{T}, A::AbstractArray) floor.(T, A)
@deprecate floor(A::AbstractArray, digits::Integer, base::Integer = 10) floor.(A, 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 (:trunc,:ceil,:round)
@eval begin
function ($f){T,R}(::Type{T}, x::AbstractArray{R,1})
[ ($f)(T, y)::T for y in x ]
Expand Down
6 changes: 4 additions & 2 deletions base/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,12 @@ 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(floor), M::Bidiagonal) = Bidiagonal(floor.(M.dv), floor.(M.ev), M.isupper)
for func in (:conj, :copy, :round, :trunc, :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(floor), ::Type{T}, M::Bidiagonal) = Bidiagonal(floor.(T, M.dv), floor.(T, M.ev), M.isupper)
for func in (:round, :trunc, :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(floor), M::SymTridiagonal) = SymTridiagonal(floor.(M.dv), floor.(M.ev))
for func in (:conj, :copy, :round, :trunc, :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(floor), ::Type{T}, M::SymTridiagonal) = SymTridiagonal(floor.(T, M.dv), floor.(T, M.ev))
for func in (:round, :trunc, :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(floor), M::Tridiagonal) = Tridiagonal(floor.(M.dl), floor.(M.d), floor.(M.du), floor.(M.du2))
for func in (:conj, :copy, :round, :trunc, :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(floor), ::Type{T}, M::Tridiagonal) =
Tridiagonal(floor.(T, M.dl), floor.(T, M.d), floor.(T, M.du), floor.(T, M.du2))
for func in (:round, :trunc, :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 @@ -2277,7 +2277,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 @@ -160,8 +160,8 @@ srand(1)

@testset "Round,float,trunc,ceil" begin
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 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 round(Int,T) == Bidiagonal(round(Int,T.dv),round(Int,T.ev),T.isupper)
Expand Down
8 changes: 4 additions & 4 deletions test/linalg/tridiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ let n = 12 #Size of matrix problem to test
@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)
@test isa(floor(Int,A), SymTridiagonal)
@test floor.(Int,A) == floor.(Int,fA)
@test isa(floor.(Int,A), SymTridiagonal)
end

debug && println("Tridiagonal/SymTridiagonal mixing ops")
Expand Down Expand Up @@ -396,8 +396,8 @@ let n = 12 #Size of matrix problem to test
@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)
@test isa(floor(Int,A), Tridiagonal)
@test floor.(Int,A) == floor.(Int,fA)
@test isa(floor.(Int,A), Tridiagonal)
end

debug && println("Binary operations")
Expand Down
10 changes: 9 additions & 1 deletion 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 (trunc, round, 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
for f in (floor,)
@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 @@ -500,7 +500,7 @@ end
@test cos.(Afull) == Array(cos.(A))
# Test representatives of remaining vectorized-nonbroadcast unary functions
@test ceil(Int, Afull) == Array(ceil(Int, A))
@test floor(Int, Afull) == Array(floor(Int, A))
@test floor.(Int, Afull) == Array(floor.(Int, A))
# Tests of real, imag, abs, and abs2 for SparseMatrixCSC{Int,X}s previously elsewhere
for T in (Int, Float16, Float32, Float64, BigInt, BigFloat)
R = rand(T[1:100;], 2, 2)
Expand Down