Skip to content

Commit 6295216

Browse files
committed
Change signature of layout() (stride check is not implemented)
1 parent 8ec64f5 commit 6295216

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

src/hermite.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ impl<A> HermiteMatrix for Array<A, Ix2>
4949
}
5050
fn cholesky(self) -> Result<Self, LinalgError> {
5151
try!(self.check_square());
52-
println!("layout = {:?}", self.layout());
5352
let (n, _) = self.size();
54-
let layout = self.layout();
53+
let layout = self.layout()?;
5554
let a = try!(ImplCholesky::cholesky(layout, n, self.into_raw_vec()));
5655
let mut c = match layout {
5756
Layout::RowMajor => Array::from_vec(a).into_shape((n, n)).unwrap(),

src/matrix.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use ndarray::prelude::*;
66
use ndarray::LinalgScalar;
77
use lapack::c::Layout;
88

9-
use error::LapackError;
9+
use error::{LinalgError, StrideError};
1010
use qr::ImplQR;
1111
use svd::ImplSVD;
1212
use norm::ImplNorm;
@@ -20,19 +20,19 @@ pub trait Matrix: Sized {
2020
/// number of (rows, columns)
2121
fn size(&self) -> (usize, usize);
2222
/// Layout (C/Fortran) of matrix
23-
fn layout(&self) -> Layout;
23+
fn layout(&self) -> Result<Layout, StrideError>;
2424
/// Operator norm for L-1 norm
2525
fn norm_1(&self) -> Self::Scalar;
2626
/// Operator norm for L-inf norm
2727
fn norm_i(&self) -> Self::Scalar;
2828
/// Frobenius norm
2929
fn norm_f(&self) -> Self::Scalar;
3030
/// singular-value decomposition (SVD)
31-
fn svd(self) -> Result<(Self, Self::Vector, Self), LapackError>;
31+
fn svd(self) -> Result<(Self, Self::Vector, Self), LinalgError>;
3232
/// QR decomposition
33-
fn qr(self) -> Result<(Self, Self), LapackError>;
33+
fn qr(self) -> Result<(Self, Self), LinalgError>;
3434
/// LU decomposition
35-
fn lu(self) -> Result<(Self::Permutator, Self, Self), LapackError>;
35+
fn lu(self) -> Result<(Self::Permutator, Self, Self), LinalgError>;
3636
/// permutate matrix (inplace)
3737
fn permutate(&mut self, p: &Self::Permutator);
3838
/// permutate matrix (outplace)
@@ -52,12 +52,12 @@ impl<A> Matrix for Array<A, Ix2>
5252
fn size(&self) -> (usize, usize) {
5353
(self.rows(), self.cols())
5454
}
55-
fn layout(&self) -> Layout {
55+
fn layout(&self) -> Result<Layout, StrideError> {
5656
let strides = self.strides();
5757
if strides[0] < strides[1] {
58-
Layout::ColumnMajor
58+
Ok(Layout::ColumnMajor)
5959
} else {
60-
Layout::RowMajor
60+
Ok(Layout::RowMajor)
6161
}
6262
}
6363
fn norm_1(&self) -> Self::Scalar {
@@ -82,7 +82,7 @@ impl<A> Matrix for Array<A, Ix2>
8282
let (m, n) = self.size();
8383
ImplNorm::norm_f(m, n, self.clone().into_raw_vec())
8484
}
85-
fn svd(self) -> Result<(Self, Self::Vector, Self), LapackError> {
85+
fn svd(self) -> Result<(Self, Self::Vector, Self), LinalgError> {
8686
let strides = self.strides();
8787
let (m, n) = if strides[0] > strides[1] {
8888
self.size()
@@ -102,7 +102,7 @@ impl<A> Matrix for Array<A, Ix2>
102102
Ok((ua, sv, va))
103103
}
104104
}
105-
fn qr(self) -> Result<(Self, Self), LapackError> {
105+
fn qr(self) -> Result<(Self, Self), LinalgError> {
106106
let (n, m) = self.size();
107107
let strides = self.strides();
108108
let k = min(n, m);
@@ -136,19 +136,19 @@ impl<A> Matrix for Array<A, Ix2>
136136
}
137137
Ok((qm, rm))
138138
}
139-
fn lu(self) -> Result<(Self::Permutator, Self, Self), LapackError> {
139+
fn lu(self) -> Result<(Self::Permutator, Self, Self), LinalgError> {
140140
let (n, m) = self.size();
141141
println!("n={}, m={}", n, m);
142142
let k = min(n, m);
143-
let (p, mut a) = match self.layout() {
143+
let (p, mut a) = match self.layout()? {
144144
Layout::ColumnMajor => {
145145
println!("ColumnMajor");
146-
let (p, l) = ImplSolve::lu(self.layout(), n, m, self.clone().into_raw_vec())?;
146+
let (p, l) = ImplSolve::lu(self.layout()?, n, m, self.clone().into_raw_vec())?;
147147
(p, Array::from_vec(l).into_shape((m, n)).unwrap().reversed_axes())
148148
}
149149
Layout::RowMajor => {
150150
println!("RowMajor");
151-
let (p, l) = ImplSolve::lu(self.layout(), n, m, self.clone().into_raw_vec())?;
151+
let (p, l) = ImplSolve::lu(self.layout()?, n, m, self.clone().into_raw_vec())?;
152152
(p, Array::from_vec(l).into_shape((n, m)).unwrap())
153153
}
154154
};

src/square.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<A> SquareMatrix for Array<A, Ix2>
4343
try!(self.check_square());
4444
let (n, _) = self.size();
4545
let is_fortran_align = self.strides()[0] > self.strides()[1];
46-
let a = try!(ImplSolve::inv(self.layout(), n, self.into_raw_vec()));
46+
let a = ImplSolve::inv(self.layout()?, n, self.into_raw_vec())?;
4747
let m = Array::from_vec(a).into_shape((n, n)).unwrap();
4848
if is_fortran_align {
4949
Ok(m)

0 commit comments

Comments
 (0)