-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing new IndexStyle / type of index? #38284
Comments
This seems like an appropriate usage to me. I've got some deadlines so may not get to you quickly, but I don't think you're off-base to be thinking this way. |
I've started working on some of these ideas in TiledArrays.jl. |
I may have misunderstood the issue here. After JuliaArrays/TiledIteration.jl#23 (v0.3.0), julia> A = rand(200, 50);
julia> TileIterator(axes(A), (128,8))
2×7 TileIterator{2,Tuple{TiledIteration.CoveredRange{StepRange{Int64,Int64},TiledIteration.LengthAtMost},TiledIteration.CoveredRange{StepRange{Int64,Int64},TiledIteration.LengthAtMost}}}:
(1:128, 1:8) (1:128, 9:16) (1:128, 17:24) (1:128, 25:32) (1:128, 33:40) (1:128, 41:48) (1:128, 49:50)
(129:200, 1:8) (129:200, 9:16) (129:200, 17:24) (129:200, 25:32) (129:200, 33:40) (129:200, 41:48) (129:200, 49:50) |
The The problem is, adding a new kind of index currently requires rewriting a whole lot of code. Reduce operations, broadcasting, views, iteration, sorting, reshaping, etc. have to be rewritten algorithmically, but you also have to implement a whole system of conversions between different indices, i.e. cartesian to tile, tile to cartesian, tile of of one tiling style to tile of another tiling style and this has to work for any kind of regular tiling. This is why I thought it might be possible to hijack The idea then is to also make to_indices dispatch on IndexStyle, so as to allow different arrays to have different index styles, even if they are subtypes of each other, or otherwise related in the type tree. |
More importantly, sort, reduce, broadcast, etc. also have to dispatch on IndexStyle, for all of this to work. |
So if I understand it correctly, if Or you just want to store the tile metadata to normal array I'm a little skeptical to mix the normal array world and the fancy block array world. |
No, |
It's not very clear to me why I still don't get why we need a new |
One example where eachindex(::IndexTiled, A) = ((ti, inds) for inds in eachindex(A[ti]) for ti in eachtileindex(A)) Just to clarify, I very much intend on using |
This is indeed different from how As a concrete counter point, we don't use a |
This is exactly my worries. I'm worried that the changes to add a new
|
It might not be public, but it's there Line 266 in 539f3ce
As far as performance, in the same way that remainder division makes it slow to go from linear index to cartesian index, it is slow to go from cartesian index to tile index. The reverse is faster, especially when you have a buffer that you're filling with values from a larger array. You want to fill the buffer once, do everything you need with it and then fill it with new values for the next chunk / tile / piece. #15648 is very interesting, thanks for the link. May be hijacking |
I think you could still use an |
So, punt on the iteration order part and just tackle the multiplication being faster than remainder division part using IndexStyle? If that's the case, it isn't much of a solution for something like DIskArrays.jl because iteration order is the key issue there. Unfortunately, that's also the main thing I want to work on :(. It might help with stuff like virtual concatenation and more complex tiling though. |
Just found BlockArrays.jl. That might solve my concrete issues at the moment. I still wonder if an array interface that allows for different iteration order is possible. Not sure what role IndexStyle would have in such an interface. |
ArrayInterface.jl seems to be dealing with some of these ideas. I’ll close this, since that’s where these sorts of discussions seem to be taking place. |
That seems reasonable. There's also https://github.com/timholy/ArrayIteration.jl but the parts of it that haven't already moved to Base are mostly focused on the problem of sparsity. |
I've been working on adding a
TiledIndex
with aIndexTiled <: IndexStyle
, for all sorts of arrays that are best indexed into via an index representing the tile and an index within that tile. See issue in TiledIteration.jl. Along the way I had a few thoughts:IndexStyle
, thus allowing users to implement new index types along with efficient algorithms for those index types.Base.to_index
andBase.to_indices
. Should these dispatch on theIndexStyle
, so that indices are converted to the correct type, based on theIndexStyle
. This would allow any user defined index to work with any array type as long as the relevantto_index
andto_indices
functions are implemented!May be I've misunderstood the point of
IndexStyle
. If that's the case, can anyone point me to some resources on implementing custom indexing? The docs only have a section for adding offset indexing, but not for more complicated indexing.The text was updated successfully, but these errors were encountered: