Consider alternative syntax for slicing (Index and IndexMut)? #1316
Replies: 2 comments 5 replies
-
Moved to dicussion. This syntax and index trait is technically not feasible for ndarray - I've explored it years back. If things have changed, and new features enable it, that's great, just need a POC that shows how it works. We don't use slices, so the poc needs to use something that's sort of equivalent to array views. I think ndarray is interested in this idea, but you'll need to show that it works 🙂. Some of us have explored it and found out why it didn't work at the time. |
Beta Was this translation helpful? Give feedback.
-
Can you elaborate on this? Do you mean that the Index implementation should return ArrayView? |
Beta Was this translation helpful? Give feedback.
-
Compared to Python, ndarray crate has an obvious difference in slicing. Arguably, this is the most annoying part of ndarray library. It would be nice to be able to do something like the following:
Now with ndarray, this code would look quite nasty, but it does not have to. Rust does allow the Index operator (i.e., [])to be "overloaded" depending on the type of whatever is being used as "indexer", as in the example below:
Using this, one could have the nice syntax actually work. Obviously, this extends to higher dimensions too:
There are several "blindspots" here (such as inability to "collapse" dimensions when range is empty or contains only one element, or mix range and integer slicing), but the key question is whether the ndarray users find it useful/appropriate to make the necessary changes to the crate to enable this at all.
Beta Was this translation helpful? Give feedback.
All reactions