-
-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start working on actual LU factorization
- Loading branch information
1 parent
7352b8c
commit dc8c62a
Showing
6 changed files
with
207 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,67 @@ | ||
use crate::CscMatrix; | ||
use crate::{CscBuilder, CscMatrix}; | ||
use nalgebra::RealField; | ||
|
||
/// Constructs an LU Factorization using a left-looking approach. | ||
/// This means it will construct each column, starting from the leftmost one. | ||
pub struct LeftLookingLUFactorization<T> { | ||
/// A single matrix stores both the lower and upper triangular components | ||
l_u: CscMatrix<T> | ||
/// A single matrix stores both the lower and upper triangular components | ||
l_u: CscMatrix<T>, | ||
} | ||
|
||
impl<T: RealField> LeftLookingLUFactorization<T> { | ||
/// Construct a new sparse LU factorization | ||
/// from a given CSC matrix. | ||
pub fn new(a: &CscMatrix<T>) -> Self { | ||
assert_eq!(a.nrows(), a.ncols()); | ||
todo!(); | ||
} | ||
impl<T: RealField + Copy> LeftLookingLUFactorization<T> { | ||
/// Returns the upper triangular part of this matrix. | ||
pub fn u(&self) -> CscMatrix<T> { | ||
self.l_u.upper_triangle() | ||
} | ||
|
||
/* | ||
/// Returns the upper triangular part of this matrix. | ||
pub fn u(&self) -> CscMatrix<T> { | ||
self.l_u.lower_triangle() | ||
// TODO here need to change the diagonal entries to be 1. | ||
todo!(); | ||
} | ||
*/ | ||
|
||
/// Construct a new sparse LU factorization | ||
/// from a given CSC matrix. | ||
pub fn new(a: &CscMatrix<T>) -> Self { | ||
assert_eq!(a.nrows(), a.ncols()); | ||
let n = a.nrows(); | ||
|
||
// this initially starts as an identity matrix. | ||
// but the ones are all implicit. | ||
let mut csc_builder = CscBuilder::new(n, n); | ||
|
||
let mut val_buf = vec![]; | ||
let mut pat_buf = vec![]; | ||
|
||
for (i, col) in a.col_iter().enumerate() { | ||
let curr_mat = csc_builder.build(); | ||
|
||
curr_mat | ||
.pattern() | ||
.sparse_lower_triangular_solve(col.row_indices(), &mut pat_buf); | ||
pat_buf.sort_unstable(); | ||
val_buf.resize_with(pat_buf.len(), T::zero); | ||
|
||
// Solve the current column, assuming that it is lower triangular | ||
let x = curr_mat.sparse_lower_triangular_solve( | ||
col.row_indices(), | ||
col.values(), | ||
&pat_buf, | ||
&mut val_buf, | ||
true, | ||
); | ||
|
||
// convert builder back to matrix | ||
csc_builder = CscBuilder::from_mat(curr_mat); | ||
assert!(csc_builder.revert_to_col(i)); | ||
let _ = x; | ||
todo!(); | ||
} | ||
|
||
//csc_builder.build() | ||
todo!(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters