1
+ //! Modified Gram-Schmit orthogonalizer
2
+
1
3
use crate :: { generate:: * , inner:: * , norm:: Norm , types:: * } ;
2
4
use ndarray:: * ;
3
5
@@ -10,32 +12,47 @@ pub struct MGS<A> {
10
12
q : Vec < Array1 < A > > ,
11
13
}
12
14
13
- /// Q-matrix (unitary)
15
+ /// Q-matrix
16
+ ///
17
+ /// - Maybe **NOT** square
18
+ /// - Unitary for existing columns
19
+ ///
14
20
pub type Q < A > = Array2 < A > ;
15
- /// R-matrix (upper triangle)
21
+
22
+ /// R-matrix
23
+ ///
24
+ /// - Maybe **NOT** square
25
+ /// - Upper triangle
26
+ ///
16
27
pub type R < A > = Array2 < A > ;
17
28
18
29
impl < A : Scalar > MGS < A > {
19
- /// Create empty linear space
20
- ///
21
- /// ```rust
22
- /// # use ndarray_linalg::{mgs::*, *};
23
- /// const N: usize = 5;
24
- /// let mgs = MGS::<f32>::new(N);
25
- /// assert_eq!(mgs.dim(), N);
26
- /// assert_eq!(mgs.len(), 0);
27
- /// ```
30
+ /// Create an empty orthogonalizer
28
31
pub fn new ( dimension : usize ) -> Self {
29
32
Self {
30
33
dimension,
31
34
q : Vec :: new ( ) ,
32
35
}
33
36
}
34
37
38
+ /// Dimension of input array
35
39
pub fn dim ( & self ) -> usize {
36
40
self . dimension
37
41
}
38
42
43
+ /// Number of cached basis
44
+ ///
45
+ /// ```rust
46
+ /// # use ndarray::*;
47
+ /// # use ndarray_linalg::{mgs::*, *};
48
+ /// const N: usize = 3;
49
+ /// let mut mgs = MGS::<f32>::new(N);
50
+ /// assert_eq!(mgs.dim(), N);
51
+ /// assert_eq!(mgs.len(), 0);
52
+ ///
53
+ /// mgs.append(array![0.0, 1.0, 0.0], 1e-9).unwrap();
54
+ /// assert_eq!(mgs.len(), 1);
55
+ /// ```
39
56
pub fn len ( & self ) -> usize {
40
57
self . q . len ( )
41
58
}
@@ -66,10 +83,6 @@ impl<A: Scalar> MGS<A> {
66
83
67
84
/// Add new vector if the residual is larger than relative tolerance
68
85
///
69
- /// Panic
70
- /// -------
71
- /// - if the size of the input array mismatches to the dimension
72
- ///
73
86
/// ```rust
74
87
/// # use ndarray::*;
75
88
/// # use ndarray_linalg::{mgs::*, *};
@@ -80,12 +93,19 @@ impl<A: Scalar> MGS<A> {
80
93
/// let coef = mgs.append(array![1.0, 1.0, 0.0], 1e-9).unwrap();
81
94
/// close_l2(&coef, &array![1.0, 1.0], 1e-9);
82
95
///
83
- /// assert!(mgs.append(array![1.0, 2.0, 0.0], 1e-9).is_err()); // Fail if the vector is linearly dependent
96
+ /// // Fail if the vector is linearly dependent
97
+ /// assert!(mgs.append(array![1.0, 2.0, 0.0], 1e-9).is_err());
84
98
///
99
+ /// // You can get coefficients of dependent vector
85
100
/// if let Err(coef) = mgs.append(array![1.0, 2.0, 0.0], 1e-9) {
86
- /// close_l2(&coef, &array![2.0, 1.0, 0.0], 1e-9); // You can get coefficients of dependent vector
101
+ /// close_l2(&coef, &array![2.0, 1.0, 0.0], 1e-9);
87
102
/// }
88
103
/// ```
104
+ ///
105
+ /// Panic
106
+ /// -------
107
+ /// - if the size of the input array mismatches to the dimension
108
+ ///
89
109
pub fn append < S > ( & mut self , a : ArrayBase < S , Ix1 > , rtol : A :: Real ) -> Result < Array1 < A > , Array1 < A > >
90
110
where
91
111
A : Lapack ,
0 commit comments