Skip to content

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

@bluss bluss force-pushed the baseiter-covariant branch from c165929 to 75b5f93 Compare August 6, 2024 10:06
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 force-pushed the baseiter-covariant branch from 75b5f93 to a9605dc Compare August 6, 2024 10:09
@bluss bluss added this to the 0.16.x milestone Aug 6, 2024
// 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 force-pushed the baseiter-covariant branch from 901a998 to 00e1546 Compare August 6, 2024 10:32
@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
@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