Skip to content

Commit eb0dfa8

Browse files
authored
Merge pull request #977 from rust-ndarray/cf-preference
Require len > 1 axis for layout preference
2 parents 0526467 + ef51f56 commit eb0dfa8

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/layout/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,34 @@ mod tests {
170170
}
171171
}
172172

173+
#[test]
174+
fn no_layouts() {
175+
let a = M::zeros((5, 5));
176+
let b = M::zeros((5, 5).f());
177+
178+
// 2D row/column matrixes
179+
let arow = a.slice(s![0..1, ..]);
180+
let acol = a.slice(s![.., 0..1]);
181+
let brow = b.slice(s![0..1, ..]);
182+
let bcol = b.slice(s![.., 0..1]);
183+
assert_layouts!(arow, CORDER, FORDER);
184+
assert_not_layouts!(acol, CORDER, CPREFER, FORDER, FPREFER);
185+
assert_layouts!(bcol, CORDER, FORDER);
186+
assert_not_layouts!(brow, CORDER, CPREFER, FORDER, FPREFER);
187+
188+
// 2D row/column matrixes - now made with insert axis
189+
for &axis in &[Axis(0), Axis(1)] {
190+
let arow = a.slice(s![0, ..]).insert_axis(axis);
191+
let acol = a.slice(s![.., 0]).insert_axis(axis);
192+
let brow = b.slice(s![0, ..]).insert_axis(axis);
193+
let bcol = b.slice(s![.., 0]).insert_axis(axis);
194+
assert_layouts!(arow, CORDER, FORDER);
195+
assert_not_layouts!(acol, CORDER, CPREFER, FORDER, FPREFER);
196+
assert_layouts!(bcol, CORDER, FORDER);
197+
assert_not_layouts!(brow, CORDER, CPREFER, FORDER, FPREFER);
198+
}
199+
}
200+
173201
#[test]
174202
fn skip_layouts() {
175203
let a = M::zeros((5, 5));

src/zip/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ where
6969
} else if n > 1 && self.raw_view().reversed_axes().is_standard_layout() {
7070
Layout::f()
7171
} else if n > 1 {
72-
if self.stride_of(Axis(0)) == 1 {
72+
if self.len_of(Axis(0)) > 1 && self.stride_of(Axis(0)) == 1 {
7373
Layout::fpref()
74-
} else if self.stride_of(Axis(n - 1)) == 1 {
74+
} else if self.len_of(Axis(n - 1)) > 1 && self.stride_of(Axis(n - 1)) == 1 {
7575
Layout::cpref()
7676
} else {
7777
Layout::none()

0 commit comments

Comments
 (0)