LU Decomposition Implements (Complete Pivot) # Description It use complete pivoting LU decomposition. You can get two permutations, and LU matrices. # Caution It returns `Option ` - You should unwrap to obtain real value. `PQLU` has four field - `p`, `q`, `l`, `u`. `p`, `q` are permutations. `l`, `u` are matrices. # Examples ``` #[macro_use] use peroxide::fuga::*; use peroxide::complex::ma
(&self)
| 1953 | /// assert_eq!(u, u_exp); |
| 1954 | /// ``` |
| 1955 | fn lu(&self) -> PQLU<ComplexMatrix> { |
| 1956 | assert_eq!(self.col, self.row); |
| 1957 | let n = self.row; |
| 1958 | let len: usize = n * n; |
| 1959 | |
| 1960 | let mut l = ceye(n); |
| 1961 | let mut u = cmatrix(vec![Complex::zero(); len], n, n, self.shape); |
| 1962 | |
| 1963 | let mut temp = self.clone(); |
| 1964 | let (p, q) = gecp(&mut temp); |
| 1965 | for i in 0..n { |
| 1966 | for j in 0..i { |
| 1967 | // Inverse multiplier |
| 1968 | l[(i, j)] = -temp[(i, j)]; |
| 1969 | } |
| 1970 | for j in i..n { |
| 1971 | u[(i, j)] = temp[(i, j)]; |
| 1972 | } |
| 1973 | } |
| 1974 | // Pivoting L |
| 1975 | for i in 0..n - 1 { |
| 1976 | unsafe { |
| 1977 | let l_i = l.col_mut(i); |
| 1978 | for j in i + 1..l.col - 1 { |
| 1979 | let dst = p[j]; |
| 1980 | std::ptr::swap(l_i[j], l_i[dst]); |
| 1981 | } |
| 1982 | } |
| 1983 | } |
| 1984 | PQLU { p, q, l, u } |
| 1985 | } |
| 1986 | |
| 1987 | fn waz(&self, _d_form: Form) -> Option<WAZD<ComplexMatrix>> { |
| 1988 | unimplemented!() |