Skip to content

Commit 80b4cf7

Browse files
committed
Add Layout::resized
1 parent a07846b commit 80b4cf7

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/layout.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ impl Layout {
2222
}
2323
}
2424

25+
pub fn resized(&self, row: Row, col: Col) -> Layout {
26+
match *self {
27+
Layout::C(_) => Layout::C((row, col)),
28+
Layout::F(_) => Layout::F((col, row)),
29+
}
30+
}
31+
2532
pub fn lda(&self) -> LDA {
2633
match *self {
2734
Layout::C((_, lda)) => lda,

src/svd.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use ndarray::*;
33

44
use super::error::*;
5-
use super::layout::{Layout, AllocatedArray, AllocatedArrayMut};
5+
use super::layout::*;
66
use impl2::LapackScalar;
77

88
pub trait SVD<U, S, VT> {
@@ -20,20 +20,11 @@ impl<A, S, Su, Svt, Ss> SVD<ArrayBase<Su, Ix2>, ArrayBase<Ss, Ix1>, ArrayBase<Sv
2020
calc_u: bool,
2121
calc_vt: bool)
2222
-> Result<(Option<ArrayBase<Su, Ix2>>, ArrayBase<Ss, Ix1>, Option<ArrayBase<Svt, Ix2>>)> {
23-
let n = self.rows();
24-
let m = self.cols();
2523
let l = self.layout()?;
2624
let svd_res = A::svd(l, calc_u, calc_vt, self.as_allocated_mut()?)?;
27-
let (u, vt) = match l {
28-
Layout::C(_) => {
29-
(svd_res.u.map(|u| ArrayBase::from_shape_vec((n, n), u).unwrap()),
30-
svd_res.vt.map(|vt| ArrayBase::from_shape_vec((m, m), vt).unwrap()))
31-
}
32-
Layout::F(_) => {
33-
(svd_res.u.map(|u| ArrayBase::from_shape_vec((n, n).f(), u).unwrap()),
34-
svd_res.vt.map(|vt| ArrayBase::from_shape_vec((m, m).f(), vt).unwrap()))
35-
}
36-
};
25+
let (n, m) = l.size();
26+
let u = svd_res.u.map(|u| reconstruct(l.resized(n, n), u).unwrap());
27+
let vt = svd_res.vt.map(|vt| reconstruct(l.resized(m, m), vt).unwrap());
3728
let s = ArrayBase::from_vec(svd_res.s);
3829
Ok((u, s, vt))
3930
}

0 commit comments

Comments
 (0)