Skip to content

Commit

Permalink
Use tighter array types for round(T, Array) etc. when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
simonster committed Mar 25, 2015
1 parent ae5b7c9 commit f2c02ef
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions base/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ round{T<:Integer}(::Type{T}, x::FloatingPoint, r::RoundingMode) = trunc(T,round(
for f in (:trunc,:floor,:ceil,:round)
@eval begin
function ($f){T,R}(::Type{T}, x::AbstractArray{R,1})
T[ ($f)(T, x[i]) for i = 1:length(x) ]
[ ($f)(T, x[i])::T for i = 1:length(x) ]
end
function ($f){T,R}(::Type{T}, x::AbstractArray{R,2})
T[ ($f)(T, x[i,j]) for i = 1:size(x,1), j = 1:size(x,2) ]
[ ($f)(T, x[i,j])::T for i = 1:size(x,1), j = 1:size(x,2) ]
end
function ($f){T}(::Type{T}, x::AbstractArray)
reshape(T[ ($f)(T, x[i]) for i = 1:length(x) ], size(x))
reshape([ ($f)(T, x[i])::T for i = 1:length(x) ], size(x))
end
end
end
Expand All @@ -89,13 +89,13 @@ function round(x::AbstractArray, r::RoundingMode)
end

function round{T,R}(::Type{T}, x::AbstractArray{R,1}, r::RoundingMode)
T[ round(T, x[i], r) for i = 1:length(x) ]
[ round(T, x[i], r)::T for i = 1:length(x) ]
end
function round{T,R}(::Type{T}, x::AbstractArray{R,2}, r::RoundingMode)
T[ round(T, x[i,j], r) for i = 1:size(x,1), j = 1:size(x,2) ]
[ round(T, x[i,j], r)::T for i = 1:size(x,1), j = 1:size(x,2) ]
end
function round{T}(::Type{T}, x::AbstractArray, r::RoundingMode)
reshape(T[ round(T, x[i], r) for i = 1:length(x) ], size(x))
reshape([ round(T, x[i], r)::T for i = 1:length(x) ], size(x))
end

# adapted from Matlab File Exchange roundsd: https://www.mathworks.com/matlabcentral/fileexchange/26212
Expand Down

0 comments on commit f2c02ef

Please sign in to comment.