Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions 18 src/iterators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,15 @@ where
}
}

impl<'a, A> DoubleEndedIterator for LanesIter<'a, A, Ix1>
{
fn next_back(&mut self) -> Option<Self::Item> {
self.iter.next_back().map(|ptr| unsafe {
ArrayView::new_(ptr, Ix1(self.inner_len), Ix1(self.inner_stride as Ix))
})
}
}

// NOTE: LanesIterMut is a mutable iterator and must not expose aliasing
// pointers. Due to this we use an empty slice for the raw data (it's unused
// anyway).
Expand Down Expand Up @@ -772,6 +781,15 @@ where
}
}

impl<'a, A> DoubleEndedIterator for LanesIterMut<'a, A, Ix1>
{
fn next_back(&mut self) -> Option<Self::Item> {
self.iter.next_back().map(|ptr| unsafe {
ArrayViewMut::new_(ptr, Ix1(self.inner_len), Ix1(self.inner_stride as Ix))
})
}
}

#[derive(Debug)]
pub struct AxisIterCore<A, D> {
/// Index along the axis of the value of `.next()`, relative to the start
Expand Down
16 changes: 16 additions & 0 deletions 16 tests/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ fn double_ended() {
assert_equal(aview1(&[1, 2, 3]).into_iter().rev(), [1, 2, 3].iter().rev());
}

#[test]
fn double_ended_rows() {
let a = ArcArray::from_iter(0..8).into_shape_clone((4, 2)).unwrap();
let mut row_it = a.rows().into_iter();
assert_equal(row_it.next_back().unwrap(), &[6, 7]);
assert_equal(row_it.next().unwrap(), &[0, 1]);
assert_equal(row_it.next_back().unwrap(), &[4, 5]);
assert_equal(row_it.next_back().unwrap(), &[2, 3]);
assert!(row_it.next().is_none());
assert!(row_it.next_back().is_none());

for (row, check) in a.rows().into_iter().rev().zip(&[[6, 7], [4, 5], [2, 3], [0, 1]]) {
assert_equal(row, check);
}
}

#[test]
fn iter_size_hint() {
// Check that the size hint is correctly computed
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.