Skip to content

the trait IntoIterator is not implemented for ndarray::Zip #1182

Description

@jimy-byerley

Hello dear maintainers, and thank you for your work on this crate !
I'm currently writing some voxel-processing functions and I'm facing a strange fact: the Zip iterator-like struct of ndarray doesn't seems to implement the IntoIterator trait. It does implement however the IntoParallelIterator trait, but it is of no help in my case where I want to filter and sum over the iterator elements.

The probleme of not implementing the Iterator trait is a general concern I think, but I'm specifically trying to do something like this:

// idiomatic rust
let acc = Zip::indexed(voxel)
                .filter_map(|position, density|  {...})
                .sum()
// imperative style
let mut acc = 0.;
for (position, density) in Zip::indexed(voxel) {
    if ...  { acc += ... }
}

None of the above ways are working because of the IntoIterator trait missing. I also tried ArrayBase::indexed_iter() but it gives tuple indices instead of fixed-arrays (not convenient for further compuations); plus it iterates in the logical order so not the most efficient depending on the input strides.

Could possibily you implement IntoIterator for Zip as it already have IntoParallelIterator ?

Edit:

in fact, both Zip::indexed and ArrayBase::indexed_iter yield a tuple for index. not sure why because the docs says I should get a [usize; 3] instead. I would be much more convenient to have such an array in my opinion ... but this is an other question.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions