Skip to content

Commit 002b463

Browse files
committed
Add documentation for cholesky module
1 parent 616d85d commit 002b463

File tree

1 file changed

+60
-5
lines changed

1 file changed

+60
-5
lines changed

src/cholesky.rs

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
1-
//! Cholesky decomposition
1+
//! Cholesky decomposition of Hermitian (or real symmetric) positive definite matrices
22
//!
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+
//! ```
434
535
use ndarray::*;
636

@@ -12,19 +42,44 @@ use super::types::*;
1242

1343
pub use lapack_traits::UPLO;
1444

15-
/// Cholesky decomposition of matrix reference
45+
/// Cholesky decomposition of Hermitian (or real symmetric) positive definite matrix reference
1646
pub trait Cholesky {
1747
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`.
1856
fn cholesky(&self, UPLO) -> Result<Self::Output>;
1957
}
2058

21-
/// Cholesky decomposition
59+
/// Cholesky decomposition of Hermitian (or real symmetric) positive definite matrix
2260
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`.
2369
fn cholesky_into(self, UPLO) -> Result<Self>;
2470
}
2571

26-
/// Cholesky decomposition of mutable reference of matrix
72+
/// Cholesky decomposition of Hermitian (or real symmetric) positive definite mutable reference of matrix
2773
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`.
2883
fn cholesky_mut(&mut self, UPLO) -> Result<&mut Self>;
2984
}
3085

0 commit comments

Comments
 (0)