Skip to content

Commit 504f168

Browse files
committed
FIX: 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 d74b5ca commit 504f168

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/zip/mod.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,25 @@ where
430430
}
431431
}
432432

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

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-
683695
fn build_and<P>(self, part: P) -> Zip<($($p,)* P, ), D>
684696
where P: NdProducer<Dim=D>,
685697
{

0 commit comments

Comments
 (0)