To_indices on tuples

question

#1

Is to_indices supposed to work on tuples? I thought they supported the indexing interface. But apparently they don’t have size.

julia> to_indices((1,2,3), (1:2, ))
ERROR: MethodError: no method matching size(::Tuple{Int64,Int64,Int64})
Closest candidates are:
  size(::Tuple, ::Any) at tuple.jl:20
  size(::Any, ::Integer, ::Integer, ::Integer...) where N at abstractarray.jl:30
  size(::Char) at char.jl:13
  ...
Stacktrace:
 [1] to_indices(::Tuple{Int64,Int64,Int64}, ::Tuple{UnitRange{Int64}}) at ./indices.jl:213

This is on v0.6.1, master fails with a different error message.

to_index((1, 2, 3), 1:2) works; but I was looking for a general solution.

Somewhat related:


#2

Tuples, named tuples and dictionaries don’t support multiple-getindex. Only AbstractArray does at the moment, and to_indices is a helper function for converting : and so-on to the actual indices of a given dimension of an AbstractArray.

I’m actually a little curious what you are attempting to do with to_indices on a tuple? :slight_smile:

(Regarding going beyond scalar indexing for types other than AbstractArray, I’ve been thinking about this at https://github.com/JuliaLang/julia/issues/24019)


#3

A collection of vectors, each for a column in a dataset (with heterogeneous element type, hence the tuple) is stored in a wrapper.

An accessor is available to get the subset of columns. I want to resolve logical and other kinds of indices, to deal with a vector of Ints (for other purposes, names and metadata management etc).


#4

Arrays have lots of crazy indexing behaviors, and it simply wasn’t obvious how those generalize to other collection-like structures when I implemented that setup. In particular, it seems especially strange that tuples should support (1,2,3)[:,:,:], and to_indices is inherently multidimensional. What should that even return? Array indexing rules state that it needs to be 3-dimensional, but we don’t have ndimensional tuples.

So, yes, I intentionally limited it to AbstractArray subtypes when I put it together.