ndarray
ndarray copied to clipboard
iterators are confusing
The current framework for iteration over arrays is confusing. Issue edited because it's even more confusing than at first glance!
Common scenarios for iteration include:
- Iterating over the elements of an array
- Iterating over subviews along an axis of an array
- Iterating mutably
- Indexed iteration
- Iterating over multiple arrays in lockstep
- Parallel iteration with Rayon
Users may expect some consistent idioms with regard to how these different iterators are accessed. The ArrayBase documentation is the starting point for many users. It is currently non-obvious (at least to me) that:
- We can iterate over subviews along an axis in parallel.
Because there is
ArrayBase::par_iter()but notArrayBase::par_axis_iter(). - We can have indexed iterators over subview along an axis.
Because there is
ArrayBase::indexed_iter()but notArrayBase::indexed_axis_iter().
I may be missing it, but it appears there is no currently no way to:
- Get a parallel version of
IndexedIterwithout the overhead ofZip::indexed(). - Get a (non-parallel)
IteratorfromZip.
There are good reasons for some of these idiosyncrasies (e.g. expeditious blanket impls), but they still steepen ndarray's learning curve. Ways to address this would include:
- [ ] Adding hints about
into_par_iter()andenumerate()to the documentation forArrayBase::axis_iter(). Or adding corresponding convenience methodsArrayBase::indexed_axis_iter(). - [ ] Implementing
IntoParallelIteratorforIndexedIter. Assuming it can be more efficient thanZip::indexed(). - [ ] Implementing
IntoIteratorforZip.
What are the maintainers' views on these ideas? I would be happy to contribute pull requests with some guidance.
Needs further discussion so that the underlying abstractions are clarified - I'll be a bit unreachable during the summer, but back in a bit