1
- //! Cholesky decomposition
1
+ //! Cholesky decomposition of Hermitian (or real symmetric) positive definite matrices
2
2
//!
3
- //! https://en.wikipedia.org/wiki/Cholesky_decomposition
3
+ //! See the [Wikipedia page about Cholesky
4
+ //! decomposition](https://en.wikipedia.org/wiki/Cholesky_decomposition) for
5
+ //! more information.
6
+ //!
7
+ //! # Example
8
+ //!
9
+ //! Calculate `L` in the Cholesky decomposition `A = L * L^H`, where `A` is a
10
+ //! Hermitian (or real symmetric) positive definite matrix:
11
+ //!
12
+ //! ```
13
+ //! #[macro_use]
14
+ //! extern crate ndarray;
15
+ //! extern crate ndarray_linalg;
16
+ //!
17
+ //! use ndarray::prelude::*;
18
+ //! use ndarray_linalg::{CholeskyInto, UPLO};
19
+ //! # fn main() {
20
+ //!
21
+ //! let a: Array2<f64> = array![
22
+ //! [ 4., 12., -16.],
23
+ //! [ 12., 37., -43.],
24
+ //! [-16., -43., 98.]
25
+ //! ];
26
+ //! let lower = a.cholesky_into(UPLO::Lower).unwrap();
27
+ //! assert!(lower.all_close(&array![
28
+ //! [ 2., 0., 0.],
29
+ //! [ 6., 1., 0.],
30
+ //! [-8., 5., 3.]
31
+ //! ], 1e-9));
32
+ //! # }
33
+ //! ```
4
34
5
35
use ndarray:: * ;
6
36
@@ -12,19 +42,44 @@ use super::types::*;
12
42
13
43
pub use lapack_traits:: UPLO ;
14
44
15
- /// Cholesky decomposition of matrix reference
45
+ /// Cholesky decomposition of Hermitian (or real symmetric) positive definite matrix reference
16
46
pub trait Cholesky {
17
47
type Output ;
48
+ /// Computes the Cholesky decomposition of the Hermitian (or real
49
+ /// symmetric) positive definite matrix.
50
+ ///
51
+ /// If the argument is `UPLO::Upper`, then computes the decomposition `A =
52
+ /// U^H * U` using the upper triangular portion of `A` and returns `U`.
53
+ /// Otherwise, if the argument is `UPLO::Lower`, computes the decomposition
54
+ /// `A = L * L^H` using the lower triangular portion of `A` and returns
55
+ /// `L`.
18
56
fn cholesky ( & self , UPLO ) -> Result < Self :: Output > ;
19
57
}
20
58
21
- /// Cholesky decomposition
59
+ /// Cholesky decomposition of Hermitian (or real symmetric) positive definite matrix
22
60
pub trait CholeskyInto : Sized {
61
+ /// Computes the Cholesky decomposition of the Hermitian (or real
62
+ /// symmetric) positive definite matrix.
63
+ ///
64
+ /// If the argument is `UPLO::Upper`, then computes the decomposition `A =
65
+ /// U^H * U` using the upper triangular portion of `A` and returns `U`.
66
+ /// Otherwise, if the argument is `UPLO::Lower`, computes the decomposition
67
+ /// `A = L * L^H` using the lower triangular portion of `A` and returns
68
+ /// `L`.
23
69
fn cholesky_into ( self , UPLO ) -> Result < Self > ;
24
70
}
25
71
26
- /// Cholesky decomposition of mutable reference of matrix
72
+ /// Cholesky decomposition of Hermitian (or real symmetric) positive definite mutable reference of matrix
27
73
pub trait CholeskyMut {
74
+ /// Computes the Cholesky decomposition of the Hermitian (or real
75
+ /// symmetric) positive definite matrix, storing the result in `self` and
76
+ /// returning it.
77
+ ///
78
+ /// If the argument is `UPLO::Upper`, then computes the decomposition `A =
79
+ /// U^H * U` using the upper triangular portion of `A` and returns `U`.
80
+ /// Otherwise, if the argument is `UPLO::Lower`, computes the decomposition
81
+ /// `A = L * L^H` using the lower triangular portion of `A` and returns
82
+ /// `L`.
28
83
fn cholesky_mut ( & mut self , UPLO ) -> Result < & mut Self > ;
29
84
}
30
85
0 commit comments