Skip to content

Commit 6654b3f

Browse files
committed
Add stride check
1 parent 6295216 commit 6654b3f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/error.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::error;
44
use std::fmt;
5+
use ndarray::Ixs;
56

67
#[derive(Debug)]
78
pub struct LapackError {
@@ -45,11 +46,14 @@ impl error::Error for NotSquareError {
4546
}
4647

4748
#[derive(Debug)]
48-
pub struct StrideError {}
49+
pub struct StrideError {
50+
pub s0: Ixs,
51+
pub s1: Ixs,
52+
}
4953

5054
impl fmt::Display for StrideError {
5155
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
52-
write!(f, "invalid stride")
56+
write!(f, "invalid stride: s0={}, s1={}", self.s0, self.s1)
5357
}
5458
}
5559

src/matrix.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ impl<A> Matrix for Array<A, Ix2>
5454
}
5555
fn layout(&self) -> Result<Layout, StrideError> {
5656
let strides = self.strides();
57+
if min(strides[0], strides[1]) != 1 {
58+
return Err(StrideError {
59+
s0: strides[0],
60+
s1: strides[1],
61+
});;
62+
}
5763
if strides[0] < strides[1] {
5864
Ok(Layout::ColumnMajor)
5965
} else {

0 commit comments

Comments
 (0)