Skip to content
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

Make AxisDescription a non-tuple struct #915

Merged
merged 3 commits into from Feb 11, 2021

Conversation

jturner314
Copy link
Member

Closes #914.

@jturner314 jturner314 force-pushed the make-axisdescription-non-tuple branch from 09c7924 to 1f0a72a Compare February 9, 2021 00:28
@@ -560,11 +560,11 @@ where
(0..self.ndim()).for_each(|ax| {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry if too frivolous, but I missed before that style wise this would be preferred to be a regular for loop. Slightly more idiomatic and avoids creating a few more functions to codegen.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, no problem. I've added that change.

I guess I'm used to using for_each instead of for loops whenever possible because, for some iterators, for_each can be faster. For a range iterator like this, though, that's probably a premature optimization, and you're right that a for loop is more idiomatic and avoids the extra closure.

The docs say:

It's generally more idiomatic to use a for loop, but for_each may be more legible when processing items at the end of longer iterator chains. In some cases for_each may also be faster than a loop, because it will use internal iteration on adaptors like Chain.

I wonder if the compiler could be changed to automatically implement for loops using for_each instead of next when possible.

@bluss bluss merged commit 13c1999 into rust-ndarray:master Feb 11, 2021
@bluss
Copy link
Member

bluss commented Feb 11, 2021

Thanks

@jturner314 jturner314 deleted the make-axisdescription-non-tuple branch February 11, 2021 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make AxisDescription a non-tuple-struct
2 participants