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 iterators covariant in element type #1417

Merged
merged 2 commits into from
Aug 6, 2024
Merged

Make iterators covariant in element type #1417

merged 2 commits into from
Aug 6, 2024

Conversation

bluss
Copy link
Member

@bluss bluss commented Aug 6, 2024

The internal Baseiter type underlies most of the ndarray iterators, and it used *mut A for element type A. Update it to use NonNull<A> which behaves identically except it's guaranteed to be non-null and is covariant w.r.t the parameter A.

Add compile test from the issue.
The second commit continues the "conversion", using NonNull more consistently
in Baseiter's Iterator impl.

Fixes #1290

The internal Baseiter type underlies most of the ndarray iterators, and
it used `*mut A` for element type A. Update it to use `NonNull<A>` which
behaves identically except it's guaranteed to be non-null and is
covariant w.r.t the parameter A.

Add compile test from the issue.

Fixes #1290
@bluss bluss added this to the 0.16.x milestone Aug 6, 2024
@@ -907,7 +907,7 @@ where D: Dimension

// iter is a raw pointer iterator traversing the array in memory order now with the
// sorted axes.
let mut iter = Baseiter::new(self_.ptr.as_ptr(), self_.dim, self_.strides);
let mut iter = Baseiter::new(self_.ptr, self_.dim, self_.strides);
Copy link
Member Author

Choose a reason for hiding this comment

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

Review note: it's evident that Baseiter is constructed from a NonNull everywhere, which means that its non-null requirement is easily fulfilled.

Complete the transition to using NonNull as the raw pointer type by
using it as Baseiter's iterator element type.
@bluss bluss added this pull request to the merge queue Aug 6, 2024
Merged via the queue into master with commit f7e4750 Aug 6, 2024
11 checks passed
@bluss bluss deleted the baseiter-covariant branch August 6, 2024 10:45
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.

ndarray iterators don't always work well with impl Iterator
1 participant