Skip to content

Commit

Permalink
Fix is_standard_layout for some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner314 committed Nov 17, 2018
1 parent 104d53c commit f3c4441
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/impl_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,11 +1025,10 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
/// contiguous in memory, it has custom strides, etc.
pub fn is_standard_layout(&self) -> bool {
fn is_standard_layout<D: Dimension>(dim: &D, strides: &D) -> bool {
let defaults = dim.default_strides();
if strides.equal(&defaults) {
if dim.slice().iter().any(|&d| d == 0) {
return true;
}
if dim.ndim() == 1 { return false; }
let defaults = dim.default_strides();
// check all dimensions -- a dimension of length 1 can have unequal strides
for (&dim, &s, &ds) in izip!(dim.slice(), strides.slice(), defaults.slice()) {
if dim != 1 && s != ds {
Expand Down
4 changes: 4 additions & 0 deletions tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,10 @@ fn standard_layout()
assert!(x1.is_standard_layout());
let x2 = a.subview(Axis(1), 0);
assert!(!x2.is_standard_layout());
let x3 = ArrayView1::from_shape(1.strides(2), &[1]).unwrap();
assert!(x3.is_standard_layout());
let x4 = ArrayView2::from_shape((0, 2).strides((0, 1)), &[1, 2]).unwrap();
assert!(x4.is_standard_layout());
}

#[test]
Expand Down

0 comments on commit f3c4441

Please sign in to comment.