1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::matrix::Matrix;
use crate::{lu_decomposed::LUDecomposed, types::Type};
use lapack::dgetrf;
impl<T> Matrix<T>
where
T: Type,
{
pub fn lud(mut self) -> Result<LUDecomposed<T>, String> {
let mut ipiv = vec![0; self.rows.min(self.columns)];
let mut info = 0;
unsafe {
dgetrf(
self.rows as i32,
self.columns as i32,
&mut self.elements,
self.rows as i32,
&mut ipiv,
&mut info,
);
}
match info {
0 => Ok(LUDecomposed::new(self.transmute(), ipiv)),
i => Err(i.to_string()),
}
}
}