Skip to content

Commit 4a96e4d

Browse files
committed
Use into_matrix
1 parent 5f2b598 commit 4a96e4d

File tree

1 file changed

+5
-24
lines changed

1 file changed

+5
-24
lines changed

ndarray-linalg/src/svd.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
//!
33
//! [Wikipedia article on SVD](https://en.wikipedia.org/wiki/Singular_value_decomposition)
44
5+
use crate::{convert::*, error::*, layout::*, types::*};
56
use ndarray::*;
67

7-
use super::error::*;
8-
use super::layout::*;
9-
use super::types::*;
10-
118
/// singular-value decomposition of matrix reference
129
pub trait SVD {
1310
type U;
@@ -98,27 +95,11 @@ where
9895
let l = self.layout()?;
9996
let svd_res = unsafe { A::svd(l, calc_u, calc_vt, self.as_allocated_mut()?)? };
10097
let (n, m) = l.size();
101-
let n = n as usize;
102-
let m = m as usize;
103-
104-
let u = svd_res.u.map(|u| {
105-
assert_eq!(u.len(), n * n);
106-
match l {
107-
MatrixLayout::F { .. } => Array::from_shape_vec((n, n).f(), u),
108-
MatrixLayout::C { .. } => Array::from_shape_vec((n, n), u),
109-
}
110-
.unwrap()
111-
});
112-
113-
let vt = svd_res.vt.map(|vt| {
114-
assert_eq!(vt.len(), m * m);
115-
match l {
116-
MatrixLayout::F { .. } => Array::from_shape_vec((m, m).f(), vt),
117-
MatrixLayout::C { .. } => Array::from_shape_vec((m, m), vt),
118-
}
119-
.unwrap()
120-
});
12198

99+
let u = svd_res.u.map(|u| into_matrix(l.resized(n, n), u).unwrap());
100+
let vt = svd_res
101+
.vt
102+
.map(|vt| into_matrix(l.resized(m, m), vt).unwrap());
122103
let s = ArrayBase::from(svd_res.s);
123104
Ok((u, s, vt))
124105
}

0 commit comments

Comments
 (0)