Skip to content

Commit

Permalink
Merge pull request #862 from jturner314/fix-zip-indexed-0dim
Browse files Browse the repository at this point in the history
Fix Zip::indexed for the 0-dimensional case
  • Loading branch information
bluss authored Dec 14, 2020
2 parents 3a2040d + e12d11d commit cb2dedb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/zip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,12 +691,14 @@ impl<P, D> Zip<P, D>
where
D: Dimension,
{
fn apply_core<F, Acc>(&mut self, acc: Acc, function: F) -> FoldWhile<Acc>
fn apply_core<F, Acc>(&mut self, acc: Acc, mut function: F) -> FoldWhile<Acc>
where
F: FnMut(Acc, P::Item) -> FoldWhile<Acc>,
P: ZippableTuple<Dim = D>,
{
if self.layout.is(CORDER | FORDER) {
if self.dimension.ndim() == 0 {
function(acc, unsafe { self.parts.as_ref(self.parts.as_ptr()) })
} else if self.layout.is(CORDER | FORDER) {
self.apply_core_contiguous(acc, function)
} else {
self.apply_core_strided(acc, function)
Expand Down
13 changes: 13 additions & 0 deletions tests/azip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,19 @@ fn test_clone() {
});
}

#[test]
fn test_indices_0() {
let a1 = arr0(3);

let mut count = 0;
Zip::indexed(&a1).apply(|i, elt| {
count += 1;
assert_eq!(i, ());
assert_eq!(*elt, 3);
});
assert_eq!(count, 1);
}

#[test]
fn test_indices_1() {
let mut a1 = Array::default(12);
Expand Down

0 comments on commit cb2dedb

Please sign in to comment.