Skip to content

Add an iter_axis function to get subviews along an axis #57

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

Merged
merged 3 commits into from
Jan 16, 2016

Conversation

vbarrielle
Copy link
Contributor

This enables for instance iterating along the columns of a matrix.

Right now the test coverage is basic, so I'll probably add more tests before it is mergeable.

@vbarrielle vbarrielle changed the title Add an iter_axis function to get subviews along an axis WIP Add an iter_axis function to get subviews along an axis Jan 15, 2016
/// the iterator element
/// is a 2 × 2 subview (and there are 3 in total).
///
/// Iterator element is `ArrayView<A, D::Smaller>` (read-only array view).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should say that it panics if axis is out of bounds

@bluss
Copy link
Member

bluss commented Jan 16, 2016

Thanks. Tests look good enough, it's the same iterator struct. I think we can reuse OuterIter without penalty, seems natural in fact.

Can we rename this? .subviews() seems like a natural name? We also want the mutable version.

@vbarrielle
Copy link
Contributor Author

Sure subviews is a nice name. I'll change that when I'm back on my computer.

@bluss
Copy link
Member

bluss commented Jan 16, 2016

axis_iter is fine too (same convention as the rest of the iterator methods I think). Methods shouldn't really have iter-names I think, pluralized names are better? I'm not sure..

@vbarrielle vbarrielle changed the title WIP Add an iter_axis function to get subviews along an axis Add an iter_axis function to get subviews along an axis Jan 16, 2016
@vbarrielle
Copy link
Contributor Author

So I renamed to axis_iter, looked like the best of the 3 possibilities. Ad I implemented the mutable iteration as well.

// ...
let mut a = a.to_owned();

for mut subview in a.axis_iter_mut(1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mut subview; it's sad quirks like this because we have no user-defined DSTs (views should be unsized like slices I think).

@bluss
Copy link
Member

bluss commented Jan 16, 2016

Thank you! I'll fixup the panic info; I don't like using headings in module docs (it doesn't work in many ways).

bluss added a commit that referenced this pull request Jan 16, 2016
Add an iter_axis function to get subviews along an axis
@bluss bluss merged commit 52e145f into rust-ndarray:master Jan 16, 2016
@vbarrielle vbarrielle deleted the iter_axis branch January 17, 2016 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants