I have one scenario that happens all the time. I get a vector of vectors and I need to obtain each component individually to perform some analyses and plot the data. Today, I do:
If I had to pick, Iâd pick the former because itâs strange to think of a dotted instance as something that is iterated. I would prefer neither because itâs simpler to understand if we always dot the callable.
TLDR: there are three conflicting meanings to what A.[I, J] could possibly mean:
You are implicitly assuming A is a collection of arrays and you want to perform the same indexing operation over all of them (this would be getindex.(A, (I,), (J,)))
You are implicitly assuming A is a single array and you want to broadcast over the passed indices â great for fusing these accesses or doing âdiagonalâ indexing (this would be getindex.((A,), I, J))
Or you (probably donât) want both the array and the indices to participate in the broadcast simultaneously (this would be getindex.(A, I, J))
I get it, but like⌠does anyone look at that and not expect the second one? I understand you could interpret other ways, but assuming A is an array of arrays in the first and last case seems IMO contrarian and not really the way most people would read that syntax. Maybe someone will say differently, but I havenât seen someone outside of that thread assume it would or could mean anything but getindex.((A,), I, J) like OP says. This is really a case of âperfect is the enemy of goodâ in my view.
Yes, both me and OP. I often miss a generalization of first, last that work for any index, and have often wanted exactly whatâs requested in OP.
Edit: after having read your post again, Iâm not quite sure which one youâre arguing for. In any case, I tend to miss the same functionality as OP.
Wrt developing multi indices access, as in getindex.(Ref(x), is), further: also consider a more principled approach of GitHub - andyferris/Indexing.jl: Generalized indexing for Julia. There Y = getindices(X, I) always implies that Y has the same indices as I with values of X:
getindices(container, indices)
Return an indexable container with indices `keys(indices)` and values `container[i]` for
`i â values(indices)`. This generalizes scalar `getindex(container, index)` for multiple
indices, for dictionaries, tuples, named tuples, etc.