Skip to content

Commit cb2dedb

Browse files
authored
Merge pull request #862 from jturner314/fix-zip-indexed-0dim
Fix Zip::indexed for the 0-dimensional case
2 parents 3a2040d + e12d11d commit cb2dedb

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/zip/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -691,12 +691,14 @@ impl<P, D> Zip<P, D>
691691
where
692692
D: Dimension,
693693
{
694-
fn apply_core<F, Acc>(&mut self, acc: Acc, function: F) -> FoldWhile<Acc>
694+
fn apply_core<F, Acc>(&mut self, acc: Acc, mut function: F) -> FoldWhile<Acc>
695695
where
696696
F: FnMut(Acc, P::Item) -> FoldWhile<Acc>,
697697
P: ZippableTuple<Dim = D>,
698698
{
699-
if self.layout.is(CORDER | FORDER) {
699+
if self.dimension.ndim() == 0 {
700+
function(acc, unsafe { self.parts.as_ref(self.parts.as_ptr()) })
701+
} else if self.layout.is(CORDER | FORDER) {
700702
self.apply_core_contiguous(acc, function)
701703
} else {
702704
self.apply_core_strided(acc, function)

tests/azip.rs

+13
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,19 @@ fn test_clone() {
303303
});
304304
}
305305

306+
#[test]
307+
fn test_indices_0() {
308+
let a1 = arr0(3);
309+
310+
let mut count = 0;
311+
Zip::indexed(&a1).apply(|i, elt| {
312+
count += 1;
313+
assert_eq!(i, ());
314+
assert_eq!(*elt, 3);
315+
});
316+
assert_eq!(count, 1);
317+
}
318+
306319
#[test]
307320
fn test_indices_1() {
308321
let mut a1 = Array::default(12);

0 commit comments

Comments
 (0)