Skip to content

Commit b33fd0d

Browse files
committed
Add test and bug fix
1 parent fe4efae commit b33fd0d

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/krylov/arnoldi.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ where
6868

6969
impl<A, S, F, Ortho> Iterator for Arnoldi<A, S, F, Ortho>
7070
where
71-
A: Scalar,
71+
A: Scalar + Lapack,
7272
S: DataMut<Elem = A>,
7373
F: Fn(&mut ArrayBase<S, Ix1>),
7474
Ortho: Orthogonalizer<Elem = A>,
@@ -78,15 +78,14 @@ where
7878
fn next(&mut self) -> Option<Self::Item> {
7979
(self.a)(&mut self.v);
8080
let result = self.ortho.div_append(&mut self.v);
81-
azip!(mut v(&mut self.v) in { *v = v.div_real(result.residual_norm()) });
81+
let norm = self.v.norm_l2();
82+
azip!(mut v(&mut self.v) in { *v = v.div_real(norm) });
8283
match result {
8384
AppendResult::Added(coef) => {
84-
dbg!(&coef);
8585
self.h.push(coef.clone());
8686
Some(coef)
8787
}
8888
AppendResult::Dependent(coef) => {
89-
dbg!(&coef);
9089
self.h.push(coef);
9190
None
9291
}
@@ -135,7 +134,7 @@ where
135134
#[cfg(test)]
136135
mod tests {
137136
use super::*;
138-
use crate::generate::*;
137+
use crate::{assert::*, generate::*};
139138

140139
#[test]
141140
fn aq_qh() {
@@ -146,23 +145,26 @@ mod tests {
146145
println!("A = \n{:?}", &a);
147146
println!("Q = \n{:?}", &q);
148147
println!("H = \n{:?}", &h);
148+
let aq = a.dot(&q);
149+
let qh = q.dot(&h);
149150
println!("AQ = \n{:?}", a.dot(&q));
150151
println!("QH = \n{:?}", q.dot(&h));
151-
panic!()
152+
close_l2(&aq, &qh, 1e-9);
152153
}
153154

154155
#[test]
155156
fn aq_qh_random() {
156157
let a: Array2<f64> = random((5, 5));
157-
let mut v = Array::zeros(5);
158-
v[0] = 1.0;
158+
let v: Array1<f64> = random(5);
159159
let (q, h) = arnoldi_mgs(a.clone(), v, 1e-9);
160160
println!("A = \n{:?}", &a);
161161
println!("Q = \n{:?}", &q);
162162
println!("H = \n{:?}", &h);
163-
println!("AQ = \n{:?}", a.dot(&q));
164-
println!("QH = \n{:?}", q.dot(&h));
165-
panic!()
163+
let aq = a.dot(&q);
164+
let qh = q.dot(&h);
165+
println!("AQ = \n{:?}", &aq);
166+
println!("QH = \n{:?}", &qh);
167+
close_l2(&aq, &qh, 1e-9);
166168
}
167169

168170
}

0 commit comments

Comments
 (0)