11///! Locally Optimal Block Preconditioned Conjugated
22///!
33///! This module implements the Locally Optimal Block Preconditioned Conjugated (LOBPCG) algorithm,
4- ///which can be used as a solver for large symmetric positive definite eigenproblems.
5-
4+ ///which can be used as a solver for large symmetric positive definite eigenproblems.
65use crate :: error:: { LinalgError , Result } ;
76use crate :: { cholesky:: * , close_l2, eigh:: * , norm:: * , triangular:: * } ;
87use crate :: { Lapack , Scalar } ;
@@ -145,7 +144,7 @@ fn orthonormalize<T: Scalar + Lapack>(v: Array2<T>) -> Result<(Array2<T>, Array2
145144/// approximates the inverse of `a`.
146145/// * `y` - Constraints of (n,size_y), iterations are performed in the orthogonal complement of the
147146/// column-space of `y`. It must be full rank.
148- /// * `tol` - The tolerance values defines at which point the solver stops the optimization. The l2-norm
147+ /// * `tol` - The tolerance values defines at which point the solver stops the optimization. The l2-norm
149148/// of the residual is compared to this value and the eigenvalue approximation returned if below
150149/// the threshold.
151150/// * `maxiter` - The maximal number of iterations
@@ -188,8 +187,8 @@ pub fn lobpcg<A: Scalar + Lapack + PartialOrd + Default, F: Fn(ArrayView2<A>) ->
188187
189188 apply_constraints ( x. view_mut ( ) , & fact_yy, y. view ( ) ) ;
190189 Some ( fact_yy)
191- } ,
192- None => None
190+ }
191+ None => None ,
193192 } ;
194193
195194 // orthonormalize the initial guess and calculate matrices AX and XAX
@@ -477,7 +476,7 @@ mod tests {
477476 if ground_truth_eigvals. len ( ) == num {
478477 close_l2 ( & Array1 :: from ( ground_truth_eigvals. to_vec ( ) ) , & vals, 5e-2 )
479478 }
480- } ,
479+ }
481480 EigResult :: NoResult ( err) => panic ! ( "Did not converge: {:?}" , err) ,
482481 }
483482 }
@@ -490,7 +489,7 @@ mod tests {
490489 ] ) ;
491490 let a = Array2 :: from_diag ( & diag) ;
492491
493- check_eigenvalues ( & a, Order :: Largest , 3 , & [ 20. , 19. , 18. ] ) ;
492+ check_eigenvalues ( & a, Order :: Largest , 3 , & [ 20. , 19. , 18. ] ) ;
494493 check_eigenvalues ( & a, Order :: Smallest , 3 , & [ 1. , 2. , 3. ] ) ;
495494 }
496495
@@ -513,12 +512,10 @@ mod tests {
513512
514513 #[ test]
515514 fn test_eigsolver_constrainted ( ) {
516- let diag = arr1 ( & [
517- 1. , 2. , 3. , 4. , 5. , 6. , 7. , 8. , 9. , 10.
518- ] ) ;
515+ let diag = arr1 ( & [ 1. , 2. , 3. , 4. , 5. , 6. , 7. , 8. , 9. , 10. ] ) ;
519516 let a = Array2 :: from_diag ( & diag) ;
520517 let x: Array2 < f64 > = Array2 :: random ( ( 10 , 1 ) , Uniform :: new ( 0.0 , 1.0 ) ) ;
521- let y: Array2 < f64 > = arr2 ( & [ [ 1.0 , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ] ] ) . reversed_axes ( ) ;
518+ let y: Array2 < f64 > = arr2 ( & [ [ 1.0 , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ] ] ) . reversed_axes ( ) ;
522519
523520 let result = lobpcg ( |y| a. dot ( & y) , x, None , Some ( y) , 1e-10 , 100 , Order :: Smallest ) ;
524521 dbg ! ( & result) ;
@@ -535,8 +532,12 @@ mod tests {
535532
536533 // should be the second eigenvalue
537534 close_l2 ( & vals, & Array1 :: from ( vec ! [ 2.0 ] ) , 1e-2 ) ;
538- close_l2 ( & vecs. column ( 0 ) . mapv ( |x| x. abs ( ) ) , & arr1 ( & [ 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 ] ) , 1e-5 ) ;
539- } ,
535+ close_l2 (
536+ & vecs. column ( 0 ) . mapv ( |x| x. abs ( ) ) ,
537+ & arr1 ( & [ 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 ] ) ,
538+ 1e-5 ,
539+ ) ;
540+ }
540541 EigResult :: NoResult ( err) => panic ! ( "Did not converge: {:?}" , err) ,
541542 }
542543 }
0 commit comments