Skip to content

Commit 840bf26

Browse files
committed
Fix document and pub setting
1 parent cc94837 commit 840bf26

File tree

3 files changed

+39
-28
lines changed

3 files changed

+39
-28
lines changed

src/krylov/householder.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
//! Householder reflection
2+
//!
3+
//! - [Householder transformation - Wikipedia](https://en.wikipedia.org/wiki/Householder_transformation)
4+
//!
5+
16
use super::*;
27
use crate::{inner::*, norm::*};
38
use num_traits::One;
@@ -16,7 +21,11 @@ where
1621
alpha
1722
}
1823

19-
/// Take a reflection using `w`
24+
/// Take a reflection `P = I - 2ww^T`
25+
///
26+
/// Panic
27+
/// ------
28+
/// - if the size of `w` and `a` mismaches
2029
pub fn reflect<A, S1, S2>(w: &ArrayBase<S1, Ix1>, a: &mut ArrayBase<S2, Ix1>)
2130
where
2231
A: Scalar + Lapack,
@@ -155,7 +164,7 @@ impl<A: Scalar + Lapack> Orthogonalizer for Householder<A> {
155164
}
156165
}
157166

158-
/// Online QR decomposition of vectors
167+
/// Online QR decomposition using Householder reflection
159168
pub fn householder<A, S>(
160169
iter: impl Iterator<Item = ArrayBase<S, Ix1>>,
161170
dim: usize,

src/krylov/mgs.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,6 @@ use super::*;
44
use crate::{generate::*, inner::*, norm::Norm};
55

66
/// Iterative orthogonalizer using modified Gram-Schmit procedure
7-
///
8-
/// ```rust
9-
/// # use ndarray::*;
10-
/// # use ndarray_linalg::{krylov::*, *};
11-
/// let mut mgs = MGS::new(3);
12-
/// let coef = mgs.append(array![0.0, 1.0, 0.0], 1e-9).unwrap();
13-
/// close_l2(&coef, &array![1.0], 1e-9);
14-
///
15-
/// let coef = mgs.append(array![1.0, 1.0, 0.0], 1e-9).unwrap();
16-
/// close_l2(&coef, &array![1.0, 1.0], 1e-9);
17-
///
18-
/// // Fail if the vector is linearly dependent
19-
/// assert!(mgs.append(array![1.0, 2.0, 0.0], 1e-9).is_err());
20-
///
21-
/// // You can get coefficients of dependent vector
22-
/// if let Err(coef) = mgs.append(array![1.0, 2.0, 0.0], 1e-9) {
23-
/// close_l2(&coef, &array![2.0, 1.0, 0.0], 1e-9);
24-
/// }
25-
/// ```
267
#[derive(Debug, Clone)]
278
pub struct MGS<A> {
289
/// Dimension of base space
@@ -31,7 +12,7 @@ pub struct MGS<A> {
3112
q: Vec<Array1<A>>,
3213
}
3314

34-
impl<A: Scalar> MGS<A> {
15+
impl<A: Scalar + Lapack> MGS<A> {
3516
/// Create an empty orthogonalizer
3617
pub fn new(dimension: usize) -> Self {
3718
Self {
@@ -45,9 +26,8 @@ impl<A: Scalar> MGS<A> {
4526
/// - Returned array is coefficients and residual norm
4627
/// - `a` will contain the residual vector
4728
///
48-
fn orthogonalize<S>(&self, a: &mut ArrayBase<S, Ix1>) -> Array1<A>
29+
pub fn orthogonalize<S>(&self, a: &mut ArrayBase<S, Ix1>) -> Array1<A>
4930
where
50-
A: Lapack,
5131
S: DataMut<Elem = A>,
5232
{
5333
assert_eq!(a.len(), self.dim());
@@ -106,7 +86,7 @@ impl<A: Scalar + Lapack> Orthogonalizer for MGS<A> {
10686
}
10787
}
10888

109-
/// Online QR decomposition of vectors using modified Gram-Schmit algorithm
89+
/// Online QR decomposition using modified Gram-Schmit algorithm
11090
pub fn mgs<A, S>(
11191
iter: impl Iterator<Item = ArrayBase<S, Ix1>>,
11292
dim: usize,

src/krylov/mod.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
use crate::types::*;
44
use ndarray::*;
55

6-
mod householder;
7-
mod mgs;
6+
pub mod householder;
7+
pub mod mgs;
88

9-
pub use householder::*;
9+
pub use householder::{householder, Householder};
1010
pub use mgs::{mgs, MGS};
1111

1212
/// Q-matrix
@@ -24,6 +24,28 @@ pub type Q<A> = Array2<A>;
2424
pub type R<A> = Array2<A>;
2525

2626
/// Trait for creating orthogonal basis from iterator of arrays
27+
///
28+
/// Example
29+
/// -------
30+
///
31+
/// ```rust
32+
/// # use ndarray::*;
33+
/// # use ndarray_linalg::{krylov::*, *};
34+
/// let mut mgs = MGS::new(3);
35+
/// let coef = mgs.append(array![0.0, 1.0, 0.0], 1e-9).unwrap();
36+
/// close_l2(&coef, &array![1.0], 1e-9);
37+
///
38+
/// let coef = mgs.append(array![1.0, 1.0, 0.0], 1e-9).unwrap();
39+
/// close_l2(&coef, &array![1.0, 1.0], 1e-9);
40+
///
41+
/// // Fail if the vector is linearly dependent
42+
/// assert!(mgs.append(array![1.0, 2.0, 0.0], 1e-9).is_err());
43+
///
44+
/// // You can get coefficients of dependent vector
45+
/// if let Err(coef) = mgs.append(array![1.0, 2.0, 0.0], 1e-9) {
46+
/// close_l2(&coef, &array![2.0, 1.0, 0.0], 1e-9);
47+
/// }
48+
/// ```
2749
pub trait Orthogonalizer {
2850
type Elem: Scalar;
2951

0 commit comments

Comments
 (0)