Skip to content

Commit 7bab818

Browse files
committed
Arnoldi::complete
1 parent 88889c1 commit 7bab818

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/krylov/arnoldi.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::*;
22
use crate::norm::Norm;
33
use num_traits::One;
4-
use std::iter::Fuse;
4+
use std::iter::*;
55

66
pub struct Arnoldi<A, S, F, Ortho>
77
where
@@ -22,14 +22,29 @@ where
2222
F: Fn(&mut ArrayBase<S, Ix1>),
2323
Ortho: Orthogonalizer<Elem = A>,
2424
{
25-
pub fn new(a: F, mut v: ArrayBase<S, Ix1>, mut ortho: Ortho) -> Fuse<Self> {
25+
pub fn new(a: F, mut v: ArrayBase<S, Ix1>, mut ortho: Ortho) -> Self {
2626
assert_eq!(ortho.len(), 0);
2727
assert!(ortho.tolerance() < One::one());
2828
// normalize before append because |v| may be smaller than ortho.tolerance()
2929
let norm = v.norm_l2();
3030
azip!(mut v(&mut v) in { *v = v.div_real(norm) });
3131
ortho.append(v.view());
32-
Iterator::fuse(Arnoldi { a, v, ortho })
32+
Arnoldi { a, v, ortho }
33+
}
34+
35+
/// Iterate until convergent
36+
pub fn complete(self) -> (Q<A>, H<A>) {
37+
let q = self.ortho.get_q();
38+
let hs: Vec<Array1<A>> = self.collect();
39+
let n = hs.len();
40+
let mut h = Array2::zeros((n, n).f());
41+
for (i, hc) in hs.iter().enumerate() {
42+
let m = std::cmp::max(n, i + 1);
43+
for j in 0..m {
44+
h[(j, i)] = hc[j];
45+
}
46+
}
47+
(q, h)
3348
}
3449

3550
/// Dimension of Krylov subspace

src/krylov/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ pub type Q<A> = Array2<A>;
2424
///
2525
pub type R<A> = Array2<A>;
2626

27+
/// H-matrix
28+
///
29+
/// - Maybe **NOT** square
30+
/// - Hessenberg matrix
31+
///
32+
pub type H<A> = Array2<A>;
33+
2734
/// Array type for coefficients to the current basis
2835
///
2936
/// - The length must be `self.len() + 1`

0 commit comments

Comments
 (0)