Skip to content

Commit 6477157

Browse files
committed
zip: Fix iteration order debug assertion in Zip
We're trying to assert the iteration order is like C-contig or C-preferred. The old assertion tripped when combining these two arrays: - shape 1, 7 strides 7, 1 (layout: CFcf) - shape 1, 7 strides 1, 2 (layout: f) The result was that the first was judged to have "no preference" and second "leaning f", total "leaning f". The debug assertion tripped a false positive because the traversal is one-dimensional, so elements are still visited in the required order. The layout judgment for the second array should ideally be "CFcf" too, but then it needs an understanding of being one-dimensional with contiguous stride of 2, which is not implemented.
1 parent 9ad7a0f commit 6477157

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/zip/mod.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,26 @@ where
430430
}
431431
}
432432

433+
impl<D, P1, P2> Zip<(P1, P2), D>
434+
where
435+
D: Dimension,
436+
P1: NdProducer<Dim=D>,
437+
P1: NdProducer<Dim=D>,
438+
{
439+
/// Debug assert traversal order is like c (including 1D case)
440+
// Method placement: only used for binary Zip at the moment.
441+
#[inline]
442+
pub(crate) fn debug_assert_c_order(self) -> Self {
443+
debug_assert!(self.layout.is(CORDER) || self.layout_tendency >= 0 ||
444+
self.dimension.slice().iter().filter(|&&d| d > 1).count() <= 1,
445+
"Assertion failed: traversal is not c-order or 1D for \
446+
layout {:?}, tendency {}, dimension {:?}",
447+
self.layout, self.layout_tendency, self.dimension);
448+
self
449+
}
450+
}
451+
452+
433453
/*
434454
trait Offset : Copy {
435455
unsafe fn offset(self, off: isize) -> Self;
@@ -673,13 +693,6 @@ macro_rules! map_impl {
673693
self.build_and(part)
674694
}
675695

676-
#[allow(unused)]
677-
#[inline]
678-
pub(crate) fn debug_assert_c_order(self) -> Self {
679-
debug_assert!(self.layout.is(CORDER) || self.layout_tendency >= 0);
680-
self
681-
}
682-
683696
fn build_and<P>(self, part: P) -> Zip<($($p,)* P, ), D>
684697
where P: NdProducer<Dim=D>,
685698
{

0 commit comments

Comments
 (0)