Skip to content

Commit 2c4ed3d

Browse files
committed
Replace orthogonalize into coeff
1 parent 54ff3b1 commit 2c4ed3d

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

src/krylov/mgs.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,12 @@ impl<A: Scalar> MGS<A> {
3939
q: Vec::new(),
4040
}
4141
}
42-
}
43-
44-
impl<A: Scalar + Lapack> Orthogonalizer for MGS<A> {
45-
type Elem = A;
46-
47-
fn dim(&self) -> usize {
48-
self.dimension
49-
}
50-
51-
fn len(&self) -> usize {
52-
self.q.len()
53-
}
5442

43+
/// Orthogonalize given vector against to the current basis
44+
///
45+
/// - Returned array is coefficients and residual norm
46+
/// - `a` will contain the residual vector
47+
///
5548
fn orthogonalize<S>(&self, a: &mut ArrayBase<S, Ix1>) -> Array1<A>
5649
where
5750
A: Lapack,
@@ -69,6 +62,27 @@ impl<A: Scalar + Lapack> Orthogonalizer for MGS<A> {
6962
coef[self.len()] = A::from_real(nrm);
7063
coef
7164
}
65+
}
66+
67+
impl<A: Scalar + Lapack> Orthogonalizer for MGS<A> {
68+
type Elem = A;
69+
70+
fn dim(&self) -> usize {
71+
self.dimension
72+
}
73+
74+
fn len(&self) -> usize {
75+
self.q.len()
76+
}
77+
78+
fn coeff<S>(&self, a: ArrayBase<S, Ix1>) -> Array1<A>
79+
where
80+
A: Lapack,
81+
S: Data<Elem = A>,
82+
{
83+
let mut a = a.into_owned();
84+
self.orthogonalize(&mut a)
85+
}
7286

7387
fn append<S>(&mut self, a: ArrayBase<S, Ix1>, rtol: A::Real) -> Result<Array1<A>, Array1<A>>
7488
where

src/krylov/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@ pub trait Orthogonalizer {
4040
self.len() == 0
4141
}
4242

43-
/// Orthogonalize given vector using current basis
43+
/// Calculate the coefficient to the given basis and residual norm
44+
///
45+
/// - The length of the returned array must be `self.len() + 1`
46+
/// - Last component is the residual norm
4447
///
4548
/// Panic
4649
/// -------
4750
/// - if the size of the input array mismatches to the dimension
4851
///
49-
fn orthogonalize<S>(&self, a: &mut ArrayBase<S, Ix1>) -> Array1<Self::Elem>
52+
fn coeff<S>(&self, a: ArrayBase<S, Ix1>) -> Array1<Self::Elem>
5053
where
51-
S: DataMut<Elem = Self::Elem>;
54+
S: Data<Elem = Self::Elem>;
5255

5356
/// Add new vector if the residual is larger than relative tolerance
5457
///

0 commit comments

Comments
 (0)