From a4c2ca941dc90078aca7ceefca9210912b662e2e Mon Sep 17 00:00:00 2001 From: Mateusz Kowalczyk Date: Mon, 30 Aug 2021 11:09:53 +0900 Subject: [PATCH] Allow constructing Cholesky struct directly This is useful if there the data for the matrix comes from elsewhere, such as a custom algorithm. One such use-case can be seen https://github.com/nestordemeure/friedrich/issues/43 where we do special handling for the try_sqrt or is_zero cases that would normally fail the decomposition in `Cholesky::new()`. --- src/linalg/cholesky.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/linalg/cholesky.rs b/src/linalg/cholesky.rs index 51da364f..f6bbda1b 100644 --- a/src/linalg/cholesky.rs +++ b/src/linalg/cholesky.rs @@ -74,6 +74,14 @@ where Cholesky { chol: matrix } } + /// Uses the given matrix as-is without any checks or modifications as the + /// Cholesky decomposition. + /// + /// It is up to the user to ensure all invariants hold. + pub fn pack_dirty(matrix: OMatrix) -> Self { + Cholesky { chol: matrix } + } + /// Retrieves the lower-triangular factor of the Cholesky decomposition with its strictly /// upper-triangular part filled with zeros. pub fn unpack(mut self) -> OMatrix {