# Fill function requiring same Int type in the tuple

**URL:** <https://discourse.julialang.org/t/fill-function-requiring-same-int-type-in-the-tuple/7660>\
**Category:** New to Julia\
**Created:** [December 9, 2017, 7:18pm UTC](https://discourse.julialang.org/t/fill-function-requiring-same-int-type-in-the-tuple/7660 "2017-12-09T19:18:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [December 9, 2017, 7:18pm UTC](https://discourse.julialang.org/t/fill-function-requiring-same-int-type-in-the-tuple/7660/1 "2017-12-09T19:18:06Z")

</div>

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
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

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 9, 2017, 9:10pm UTC](https://discourse.julialang.org/t/fill-function-requiring-same-int-type-in-the-tuple/7660/2 "2017-12-09T21:10:05Z")

</div>

I think it should accept all mixtures of subtypes of `Integer`. Perhaps broaden the [definition](https://github.com/JuliaLang/julia/blob/ff045afdfd448a28b43b764c4d67e6ef3ed42ed0/base/indices.jl#L3) of `Dims`?

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [December 9, 2017, 10:12pm UTC](https://discourse.julialang.org/t/fill-function-requiring-same-int-type-in-the-tuple/7660/3 "2017-12-09T22:12:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [December 9, 2017, 10:19pm UTC](https://discourse.julialang.org/t/fill-function-requiring-same-int-type-in-the-tuple/7660/4 "2017-12-09T22:19:27Z")

</div>

> <https://github.com/JuliaLang/julia/issues/23029>
>
> \`\`\`
> Matrix{Float32}(3, 4) # works
> Matrix{Float32}(0x3, 0x4) # work…s 
> Matrix{Float32}((3, 4)) # works 
> 
> Matrix{Float32}((0x3, 0x4)) # errors 
> \`\`\`
> 
> Would it be possible to broaden the \`Matrix(Tuple)\` constructor to allow types \`\<: Integer\` in the Tuple?
> 
> Other constructors work:
> \`\`\`
> julia\> zeros(0x3,0x4)
> 3×4 Array{Float64,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
> 
> julia\> zeros((0x3,0x4))
> 3×4 Array{Float64,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
> \`\`\`

> <https://github.com/JuliaLang/julia/issues/23032>
>
> See #23029 for related issue. This is one example of an inconsistency between Sh…aredMatrix construction and Matrix construction:
> 
> \`\`\`
> julia\> SharedMatrix{Float32}(0x3, 0x4)
> ERROR: MethodError: Cannot \`convert\` an object of type Tuple{UInt8,UInt8} to an object of type SharedArray{Float32,2}
> This may have arisen from a call to the constructor SharedArray{Float32,2}(...),
> since type constructors fall back to convert methods.
> Stacktrace:
> \[1\] #call#605(::Array{Any,1}, ::Type{SharedArray{Float32,2}}, ::UInt8, ::Vararg{UInt8,N} where N) at ./sharedarray.jl:146
> \[2\] SharedArray{Float32,2}(::UInt8, ::UInt8) at ./sharedarray.jl:146
> \`\`\`
> 
> It would be nice if the constructors for \`SharedMatrix\` were the same as for \`Matrix\`.

> <https://github.com/JuliaLang/julia/issues/23246>
>
> Julia v0.6
> 
> \`\`\`
> a::Int64 = 5
> b::Tuple{Int64, Int64} = (a, a)
> Matrix{Int64}(…b)
> \`\`\`
> This code works, but if you replace all instances of Int64 with Int32 it does not work anymore.
> \`\`\`
> ERROR: MethodError: Cannot \`convert\` an object of type Tuple{Int32,Int32} to an object of type Array{Int32,2}
> This may have arisen from a call to the constructor Array{Int32,2}(...),
> since type constructors fall back to convert methods.
> \`\`\`
> 
> 
> But if you write it a bit different
> \`\`\`
> a::Int64 = 5
> Matrix{Int64}(a, a)
> \`\`\`
> this will work with either Int32 or Int64.
> 
> I think my first sample should work with any integer-version.

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

```julia
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

```

> [@nalimilan](#):
>
> Looks like one such method is lacking or has a too strict signature.

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