File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 11use ndarray:: * ;
22use ndarray_linalg:: * ;
33
4+ fn sorted_eigvals < T : Scalar > ( eigvals : ArrayView1 < ' _ , T > ) -> Array1 < T > {
5+ let mut indices: Vec < usize > = ( 0 ..eigvals. len ( ) ) . collect ( ) ;
6+ indices. sort_by ( |& ind1, & ind2| {
7+ let e1 = eigvals[ ind1] ;
8+ let e2 = eigvals[ ind2] ;
9+ e1. re ( )
10+ . partial_cmp ( & e2. re ( ) )
11+ . unwrap ( )
12+ . then ( e1. im ( ) . partial_cmp ( & e2. im ( ) ) . unwrap ( ) )
13+ } ) ;
14+ indices. iter ( ) . map ( |& ind| eigvals[ ind] ) . collect ( )
15+ }
16+
417// Test Av_i = e_i v_i for i = 0..n
518fn test_eig < T : Scalar > ( a : Array2 < T > , eigs : Array1 < T :: Complex > , vecs : Array2 < T :: Complex > )
619where
@@ -216,7 +229,11 @@ macro_rules! impl_test_real {
216229 fn [ <$real _eigvals_t>] ( ) {
217230 let a = test_matrix_real_t:: <$real>( ) ;
218231 let ( e, _vecs) = a. eig( ) . unwrap( ) ;
219- assert_close_l2!( & e, & answer_eig_real:: <$real>( ) , 1.0e-3 ) ;
232+ assert_close_l2!(
233+ & sorted_eigvals( e. view( ) ) ,
234+ & sorted_eigvals( answer_eig_real:: <$real>( ) . view( ) ) ,
235+ 1.0e-3
236+ ) ;
220237 }
221238
222239 #[ test]
You can’t perform that action at this time.
0 commit comments