@@ -10,11 +10,7 @@ pub struct MGS<A> {
10
10
q : Vec < Array1 < A > > ,
11
11
}
12
12
13
- /// Residual vector of orthogonalization
14
- pub type Residual < S > = ArrayBase < S , Ix1 > ;
15
- /// Residual vector of orthogonalization
16
- pub type Coefficient < A > = Array1 < A > ;
17
- /// Q-matrix (unitary matrix)
13
+ /// Q-matrix (unitary)
18
14
pub type Q < A > = Array2 < A > ;
19
15
/// R-matrix (upper triangle)
20
16
pub type R < A > = Array2 < A > ;
@@ -49,7 +45,7 @@ impl<A: Scalar> MGS<A> {
49
45
/// Panic
50
46
/// -------
51
47
/// - if the size of the input array mismaches to the dimension
52
- pub fn orthogonalize < S > ( & self , mut a : ArrayBase < S , Ix1 > ) -> ( Residual < S > , Coefficient < A > )
48
+ pub fn orthogonalize < S > ( & self , a : & mut ArrayBase < S , Ix1 > ) -> Array1 < A >
53
49
where
54
50
A : Lapack ,
55
51
S : DataMut < Elem = A > ,
@@ -59,12 +55,12 @@ impl<A: Scalar> MGS<A> {
59
55
for i in 0 ..self . len ( ) {
60
56
let q = & self . q [ i] ;
61
57
let c = q. inner ( & a) ;
62
- azip ! ( mut a, q ( q) in { * a = * a - c * q } ) ;
58
+ azip ! ( mut a ( & mut * a ) , q ( q) in { * a = * a - c * q } ) ;
63
59
coef[ i] = c;
64
60
}
65
61
let nrm = a. norm_l2 ( ) ;
66
62
coef[ self . len ( ) ] = A :: from_real ( nrm) ;
67
- ( a , coef)
63
+ coef
68
64
}
69
65
70
66
/// Add new vector if the residual is larger than relative tolerance
@@ -85,13 +81,13 @@ impl<A: Scalar> MGS<A> {
85
81
///
86
82
/// assert!(mgs.append(array![1.0, 2.0, 0.0], 1e-9).is_none()); // Cannot append dependent vector
87
83
/// ```
88
- pub fn append < S > ( & mut self , a : ArrayBase < S , Ix1 > , rtol : A :: Real ) -> Option < Coefficient < A > >
84
+ pub fn append < S > ( & mut self , a : ArrayBase < S , Ix1 > , rtol : A :: Real ) -> Option < Array1 < A > >
89
85
where
90
86
A : Lapack ,
91
87
S : Data < Elem = A > ,
92
88
{
93
- let a = a. into_owned ( ) ;
94
- let ( mut a , coef) = self . orthogonalize ( a) ;
89
+ let mut a = a. into_owned ( ) ;
90
+ let coef = self . orthogonalize ( & mut a) ;
95
91
let nrm = coef[ coef. len ( ) - 1 ] . re ( ) ;
96
92
if nrm < rtol {
97
93
// Linearly dependent
0 commit comments