# To\_indices on tuples

**URL:** <https://discourse.julialang.org/t/to-indices-on-tuples/7649>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [December 9, 2017, 10:05am UTC](https://discourse.julialang.org/t/to-indices-on-tuples/7649 "2017-12-09T10:05:38Z")\
**Posts on this page:** 4\
**Page:** 1

<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, 10:05am UTC](https://discourse.julialang.org/t/to-indices-on-tuples/7649/1 "2017-12-09T10:05:38Z")

</div>

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

```julia
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:  
[https://github.com/JuliaLang/julia/issues/23822](https://github.com/JuliaLang/julia/issues/23822)

---

<div class="post-metadata">

**Author:** ![andyferris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andyferris/32/235_2.png) [@andyferris](https://discourse.julialang.org/u/andyferris)\
**Post date:** [December 9, 2017, 10:45am UTC](https://discourse.julialang.org/t/to-indices-on-tuples/7649/2 "2017-12-09T10:45:49Z")

</div>

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

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

---

<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, 10:49am UTC](https://discourse.julialang.org/t/to-indices-on-tuples/7649/3 "2017-12-09T10:49:01Z")

</div>

> [@andyferris](#):
>
> I’m actually a little curious what you are attempting to do with to\_indices on a tuple? 🙂

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 `Int`s (for other purposes, names and metadata management etc).

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [December 10, 2017, 6:34pm UTC](https://discourse.julialang.org/t/to-indices-on-tuples/7649/4 "2017-12-10T18:34:30Z")

</div>

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.
