Skip to content

Commit 57fc75c

Browse files
authored
Merge pull request #78 from jturner314/add-more-docs
Add docs for cholesky and fix docs for FactorizedH
2 parents 4d9d6cf + 002b463 commit 57fc75c

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
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

src/solveh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub trait SolveH<A: Scalar> {
8888
}
8989

9090
/// Represents the Bunch–Kaufman factorization of a Hermitian (or real
91-
/// symmetric) matrix as `A = P * U * D * U^T * P^T`.
91+
/// symmetric) matrix as `A = P * U * D * U^H * P^T`.
9292
pub struct FactorizedH<S: Data> {
9393
pub a: ArrayBase<S, Ix2>,
9494
pub ipiv: Pivot,

0 commit comments

Comments
 (0)