Deprecated warning with round.(Int64,x)



I have a type Array{Array{Float64,1},1} which I would like to round and convert to Int64. However, when I attempt to do this I get a deprecated warning which I don’t understand. I don’t understand the difference between what it says is deprecated, and what it is asking me to do. I’d appreciate any advice on how to do the conversion as simply as possible. I am using Version 0.6.0 (2017-06-19 13:05 UTC) on x86_64-w64-mingw32. I’ve provided a minimal example below.

Many thanks for your time.

julia> round.(Int64,Vector(Array{Float64,1}[[389.24, 0.0], [0.0, 292.22]]))
WARNING: round{T}(::Type{T}, x::AbstractArray) is deprecated, use round.(T, x) instead.
 [1] depwarn(::String, ::Symbol) at .\deprecated.jl:70
 [2] round(::Type{Int64}, ::Array{Float64,1}) at .\deprecated.jl:57
 [3] macro expansion at .\broadcast.jl:153 [inlined]
 [4] macro expansion at .\simdloop.jl:73 [inlined]
 [5] macro expansion at .\broadcast.jl:147 [inlined]
 [6] _broadcast!(::Base.#round, ::Array{Array{Int64,1},1}, ::Tuple{Tuple{},Tuple{Bool}}, ::Tuple{Tuple{},Tuple{Int64}}, ::Type{Int64}, ::Tuple{Array{Array{Float64,1},1}}, ::Type{Val{1}}, ::CartesianRange{CartesianIndex{1}}) at .\broadcast.jl:139
 [7] broadcast_t(::Function, ::Type{T} where T, ::Tuple{Base.OneTo{Int64}}, ::CartesianRange{CartesianIndex{1}}, ::Type{T} where T, ::Array{Array{Float64,1},1}) at .\broadcast.jl:268
 [8] broadcast_c(::Function, ::Type{Array}, ::Type{T} where T, ::Array{Array{Float64,1},1}, ::Vararg{Array{Array{Float64,1},1},N} where N) at .\broadcast.jl:314
 [9] broadcast(::Function, ::Type{T} where T, ::Array{Array{Float64,1},1}) at .\broadcast.jl:434
 [10] eval(::Module, ::Any) at .\boot.jl:235
 [11] eval_user_input(::Any, ::Base.REPL.REPLBackend) at .\REPL.jl:66
 [12] macro expansion at .\REPL.jl:97 [inlined]
 [13] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at .\event.jl:73
while loading no file, in expression starting on line 0
2-element Array{Array{Int64,1},1}:
 [389, 0]
 [0, 292]

julia> typeof(Vector(Array{Float64,1}[[389.24, 0.0], [0.0, 292.22]]))


I don’t know exactly the reason for the warning, but by simplifying your code to

round.(Int64,[[389.24, 0.0], [0.0, 292.22]])

(which is equivalent and easier to reason about)
throws the warning away.

Sorry, forget what I wrote. The warning went away after a second run, not because the code was different.


You are still applying round(Int64, ...) on each element of the array so you should do that manually. Sth like [round.(Int64, v) for v in ...]


As already noted the problem is that you need to dot broadcast a level deeper than you do. Actually doing it with two levels of dot broadcast is probably less readable than a comprehension but may give some additional insights into the problem.

julia> x = [[389.24,0.0],[0.0, 292.22]]
2-element Array{Array{Float64,1},1}:
 [389.24, 0.0]
 [0.0, 292.22]

julia> (t -> round.(Int, t)).(x)
2-element Array{Array{Int64,1},1}:
 [389, 0]
 [0, 292]