Skip to content

Commit

Permalink
Mark Elements, ElementsMut as ESI
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Jan 9, 2016
1 parent b61dc4e commit 66ff21b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ impl<'a, A> DoubleEndedIterator for ElementsBase<'a, A, Ix>
}
}

impl<'a, A> ExactSizeIterator for ElementsBase<'a, A, Ix> { }
impl<'a, A, D> ExactSizeIterator for ElementsBase<'a, A, D>
where D: Dimension,
{ }

macro_rules! either {
($value:expr, $inner:ident => $result:expr) => (
Expand Down Expand Up @@ -219,7 +221,9 @@ impl<'a, A> DoubleEndedIterator for Elements<'a, A, Ix>
}
}

impl<'a, A> ExactSizeIterator for Elements<'a, A, Ix> { }
impl<'a, A, D> ExactSizeIterator for Elements<'a, A, D>
where D: Dimension,
{ }


impl<'a, A, D: Dimension> Iterator for Indexed<'a, A, D>
Expand Down
24 changes: 22 additions & 2 deletions tests/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,36 @@ use ndarray::{
};

use itertools::assert_equal;
use itertools::{rev, enumerate};

#[test]
fn double_ended()
{
fn double_ended() {
let a = Array::linspace(0., 7., 8);
let mut it = a.iter().map(|x| *x);
assert_eq!(it.next(), Some(0.));
assert_eq!(it.next_back(), Some(7.));
assert_eq!(it.next(), Some(1.));
assert_eq!(it.rev().last(), Some(2.));
assert_equal(aview1(&[1, 2, 3]), &[1, 2, 3]);
assert_equal(rev(aview1(&[1, 2, 3])), rev(&[1, 2, 3]));
}

#[test]
fn size_hint() {
// Check that the size hint is correctly computed
let a = Array::from_iter(0..24).reshape((2, 3, 4));
let mut data = [0; 24];
for (i, elt) in enumerate(&mut data) {
*elt = i as i32;
}
assert_equal(&a, &data);
let mut it = a.iter();
let mut ans = data.iter();
assert_eq!(it.len(), ans.len());
while ans.len() > 0 {
assert_eq!(it.next(), ans.next());
assert_eq!(it.len(), ans.len());
}
}

#[test]
Expand Down

0 comments on commit 66ff21b

Please sign in to comment.