11use super :: * ;
22use crate :: norm:: Norm ;
33use num_traits:: One ;
4- use std:: iter:: Fuse ;
4+ use std:: iter:: * ;
55
66pub struct Arnoldi < A , S , F , Ortho >
77where
@@ -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
0 commit comments