FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make iterators covariant in element type by bluss · Pull Request #1417 · rust-ndarray/ndarray · GitHub

Make iterators covariant in element type - #1417

Merged
bluss merged 2 commits into
masterfrom
baseiter-covariant
Aug 6, 2024
Merged

Make iterators covariant in element type#1417
bluss merged 2 commits into
masterfrom
baseiter-covariant

Conversation

bluss commented Aug 6, 2024
edited
Loading

Copy link
Copy Markdown
Member

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 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 force-pushed the baseiter-covariant branch from 75b5f93 to a9605dc Compare August 6, 2024 10:09
bluss added this to the 0.16.x milestone Aug 6, 2024
Comment thread src/impl_owned_array.rs
// 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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 force-pushed the baseiter-covariant branch from 901a998 to 00e1546 Compare August 6, 2024 10:32
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 deleted the baseiter-covariant branch August 6, 2024 10:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL