Can't use tuple of `UInt` as index

Is this expected behavior?

julia> idx = UInt(3); A = rand(4); A[idx]
0.10882052381690266

julia> idx = (UInt(3), UInt(1)); A = rand(4, 5); A[idx]
ERROR: ArgumentError: invalid index: (0x0000000000000003, 0x0000000000000001) of type Tuple{UInt64,UInt64}
Stacktrace:
 [1] to_index(::Tuple{UInt64,UInt64}) at .\indices.jl:297
 [2] to_index(::Array{Float64,2}, ::Tuple{UInt64,UInt64}) at .\indices.jl:274
 [3] to_indices at .\indices.jl:325 [inlined]
 [4] to_indices at .\indices.jl:322 [inlined]
 [5] getindex(::Array{Float64,2}, ::Tuple{UInt64,UInt64}) at .\abstractarray.jl:1060
 [6] top-level scope at none:1

I’m writing a function that I would like to work with with UInt or Int arrays as input, but this issue (and an analogous one when using get(A, idx, 0)) is getting in the way.

You can either splat or use a CartesianIndex if you want to index a multidimensional array.

julia> A[idx...]
0.8201224060592813

julia> A[CartesianIndex(idx)]
0.8201224060592813

julia> get(A, CartesianIndex(idx), 0)
0.8201224060592813
1 Like

Splat doesn’t work in get(), but CartesianIndex() does. Thank you.

This has been solved, I just wanted to point out that it is unrelated to UInt vs Int. You simply cannot index with tuples like that, so the same thing will happen here:

jl> idx = (3, 1); A[idx]
ERROR: ArgumentError: invalid index: (3, 1) of type Tuple{Int64,Int64}

You can use get() like that with no problem, hence my issue.