Fill function requiring same Int type in the tuple


#1

I would have thought that the fill() function is smarter. Now I have to cast to the widest type before calling it… Any thoughts? Am I too picky?

julia> fill(0, (Int64(10), Int32(8)))
ERROR: MethodError: no method matching fill(::Int64, ::Tuple{Int64,Int32})
Closest candidates are:
  fill(::Any, ::Tuple{Vararg{Int64,N}} where N) at array.jl:253
  fill(::Any, ::Integer...) at array.jl:254

julia> fill(0, (Int64(10), Int64(8)))
10×8 Array{Int64,2}:
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0

Rand chokes on UInt64
#2

I think it should accept all mixtures of subtypes of Integer. Perhaps broaden the definition of Dims?


#3

I don’t think Dims should be changed. In general, the approach taken is to create convenience methods which convert all values to Int before calling the main method, to minimize the amount of code that needs to be recompiled. Looks like one such method is lacking or has a too strict signature.


#4

https://github.com/JuliaLang/julia/issues/23029
https://github.com/JuliaLang/julia/issues/23032
https://github.com/JuliaLang/julia/issues/23246

If you really want to use different Integer types, I suggest that you just call Dims of your tuple

julia> fill(0, Dims((Int64(10), Int32(8))))
10×8 Array{Int64,2}:
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0
 0  0  0  0  0  0  0  0

I’d favor just accepting Ints, since we will always convert to that internally anyway, and let the user convert with e.g. Dims instead.