iterators are confusing

Aberta
#1,043 1 comentário 3 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
5/5
Tempo estimado
Mais de uma semana
Facilidade para iniciantes
25/100
Tipo de issue
Funcionalidade
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
rust

Direção de pesquisa

Start with the ArrayBase documentation and the axis_iter(), par_iter(), indexed_iter(), IndexedIter, and Zip entry points named in the issue. Review how into_par_iter() and enumerate() are currently exposed, then seek maintainer guidance on which iterator APIs or documentation changes are wanted. Done means an agreed scope is implemented and the relevant iterator behavior and documentation are covered.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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 not ArrayBase::par_axis_iter().
  • We can have indexed iterators over subview along an axis.
    Because there is ArrayBase::indexed_iter() but not ArrayBase::indexed_axis_iter().

I may be missing it, but it appears there is no currently no way to:

  • Get a parallel version of IndexedIter without the overhead of Zip::indexed().
  • Get a (non-parallel) Iterator from Zip.

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() and enumerate() to the documentation for ArrayBase::axis_iter().
    Or adding corresponding convenience methods ArrayBase::indexed_axis_iter().
  • Implementing IntoParallelIterator for IndexedIter.
    Assuming it can be more efficient than Zip::indexed().
  • Implementing IntoIterator for Zip.

What are the maintainers' views on these ideas? I would be happy to contribute pull requests with some guidance.

Linguagem predominante
Rust
Estrelas
4.3k
Forks
391
Métricas de merge de PRs
Nenhum PR com merge em 30d

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de rust-ndarray/ndarray

Todas as issues de rust-ndarray/ndarray

Issues semelhantes

Mais issues de Rust

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.