Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Zip::indexed for the 0-dimensional case #862

Merged
merged 1 commit into from Dec 14, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/zip/mod.rs
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
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