-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cholesky decomposition rewrite: initial work #150
Merged
+656
−14
Merged
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
e1a1a0e
Add minimal internal_utils module
Andlon 5f04dcb
Basic implementation of Cholesky
Andlon 754de35
Rewrite lu unpack to use nullify from internal_utils
Andlon f3807c7
Add Cholesky benchmarks
Andlon 38b08a3
Take raw_slice_mut() in nullify
Andlon 29163f4
Rewrite Cholesky in terms of dot()
Andlon 4520bd5
Cholesky: validate diagonal entries
Andlon 91b0751
Implement det() for Cholesky
Andlon 038f129
Implement transpose_back_substitution
Andlon d243313
Implement Cholesky::solve
Andlon 8b398a1
Add benchmarks for Cholesky::solve
Andlon 5b47cd5
Rewrite transpose_back_sub.. for better data access pattern
Andlon 5c8a566
Enable previously disabled test
Andlon 2c45b7b
Implement Cholesky::inverse()
Andlon 5de2e50
Documentation for Cholesky
Andlon a4eb96c
Fix errors in Cholesky doctests
Andlon 9e28cdd
Remove stray ///
Andlon c222bb1
Remove confusing comment
Andlon f387056
Add Cholesky to decomposition module overview
Andlon 5af62fa
Deprecate .cholesky()
Andlon 04c2d77
Add warning to Cholesky::decompose
Andlon 1916c71
Rewrite Cholesky solve/inverse to return Result
Andlon 8edae5b
Merge branch 'master' into cholesky
Andlon 8dc150b
Explain determinant of empty matrix to Cholesky/PartialPivLu
Andlon 9ec0d1c
Reorder Cholesky and FullPivLu in decomposition docs
Andlon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use rulinalg::matrix::Matrix; | ||
use rulinalg::matrix::decomposition::{Cholesky, Decomposition}; | ||
use test::Bencher; | ||
|
||
#[bench] | ||
fn cholesky_decompose_unpack_100x100(b: &mut Bencher) { | ||
let n = 100; | ||
let x = Matrix::<f64>::identity(n); | ||
b.iter(|| { | ||
// Assume that the cost of cloning x is roughly | ||
// negligible in comparison with the cost of LU | ||
Cholesky::decompose(x.clone()).expect("Matrix is invertible") | ||
.unpack() | ||
}) | ||
} | ||
|
||
#[bench] | ||
fn cholesky_decompose_unpack_500x500(b: &mut Bencher) { | ||
let n = 500; | ||
let x = Matrix::<f64>::identity(n); | ||
b.iter(|| { | ||
// Assume that the cost of cloning x is roughly | ||
// negligible in comparison with the cost of LU | ||
Cholesky::decompose(x.clone()).expect("Matrix is invertible") | ||
.unpack() | ||
}) | ||
} | ||
|
||
#[bench] | ||
fn cholesky_100x100(b: &mut Bencher) { | ||
// Benchmark for legacy cholesky(). Remove when | ||
// cholesky() has been removed. | ||
let n = 100; | ||
let x = Matrix::<f64>::identity(n); | ||
b.iter(|| { | ||
x.cholesky().expect("Matrix is invertible") | ||
}) | ||
} | ||
|
||
#[bench] | ||
fn cholesky_500x500(b: &mut Bencher) { | ||
// Benchmark for legacy cholesky(). Remove when | ||
// cholesky() has been removed. | ||
let n = 500; | ||
let x = Matrix::<f64>::identity(n); | ||
b.iter(|| { | ||
x.cholesky().expect("Matrix is invertible") | ||
}) | ||
} | ||
|
||
#[bench] | ||
fn cholesky_solve_1000x1000(b: &mut Bencher) { | ||
let n = 1000; | ||
let x = Matrix::identity(n); | ||
let cholesky = Cholesky::decompose(x).unwrap(); | ||
b.iter(|| { | ||
cholesky.solve(vector![0.0; n]) | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn cholesky_solve_100x100(b: &mut Bencher) { | ||
let n = 100; | ||
let x = Matrix::identity(n); | ||
let cholesky = Cholesky::decompose(x).unwrap(); | ||
b.iter(|| { | ||
cholesky.solve(vector![0.0; n]) | ||
}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use matrix::BaseMatrixMut; | ||
use libnum::Zero; | ||
|
||
pub fn nullify_lower_triangular_part<T, M>(matrix: &mut M) | ||
where T: Zero, M: BaseMatrixMut<T> { | ||
for (i, mut row) in matrix.row_iter_mut().enumerate() { | ||
for element in row.raw_slice_mut().iter_mut().take(i) { | ||
*element = T::zero(); | ||
} | ||
} | ||
} | ||
|
||
pub fn nullify_upper_triangular_part<T, M>(matrix: &mut M) | ||
where T: Zero, M: BaseMatrixMut<T> { | ||
for (i, mut row) in matrix.row_iter_mut().enumerate() { | ||
for element in row.raw_slice_mut().iter_mut().skip(i + 1) { | ||
*element = T::zero(); | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::nullify_lower_triangular_part; | ||
use super::nullify_upper_triangular_part; | ||
|
||
#[test] | ||
fn nullify_lower_triangular_part_examples() { | ||
let mut x = matrix![1.0, 2.0, 3.0; | ||
4.0, 5.0, 6.0; | ||
7.0, 8.0, 9.0]; | ||
nullify_lower_triangular_part(&mut x); | ||
assert_matrix_eq!(x, matrix![ | ||
1.0, 2.0, 3.0; | ||
0.0, 5.0, 6.0; | ||
0.0, 0.0, 9.0 | ||
]); | ||
} | ||
|
||
#[test] | ||
fn nullify_upper_triangular_part_examples() { | ||
let mut x = matrix![1.0, 2.0, 3.0; | ||
4.0, 5.0, 6.0; | ||
7.0, 8.0, 9.0]; | ||
nullify_upper_triangular_part(&mut x); | ||
assert_matrix_eq!(x, matrix![ | ||
1.0, 0.0, 0.0; | ||
4.0, 5.0, 0.0; | ||
7.0, 8.0, 9.0 | ||
]); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -100,6 +100,8 @@ pub mod vector; | |
pub mod ulp; | ||
pub mod norm; | ||
|
||
mod internal_utils; | ||
|
||
#[cfg(test)] | ||
mod testsupport; | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this module would be better placed in the
matrix
folder, so that it issrc/matrix/utils.rs
?