1
+ use ndarray:: * ;
2
+ use ndarray_linalg:: * ;
3
+
4
+ #[ test]
5
+ fn dgeev ( ) {
6
+ // https://software.intel.com/sites/products/documentation/doclib/mkl_sa/11/mkl_lapack_examples/dgeev_ex.f.htm
7
+ let a: Array2 < f64 > = arr2 ( & [ [ -1.01 , 0.86 , -4.60 , 3.31 , -4.81 ] ,
8
+ [ 3.98 , 0.53 , -7.04 , 5.29 , 3.55 ] ,
9
+ [ 3.30 , 8.26 , -3.89 , 8.20 , -1.51 ] ,
10
+ [ 4.43 , 4.96 , -7.66 , -7.33 , 6.18 ] ,
11
+ [ 7.31 , -6.43 , -6.16 , 2.47 , 5.58 ] ] ) ;
12
+ let ( e, vecs) : ( Array1 < _ > , Array2 < _ > ) = ( & a) . eig ( ) . unwrap ( ) ;
13
+ assert_close_l2 ! ( & e,
14
+ & arr1( & [ c64:: new( 2.86 , 10.76 ) , c64:: new( 2.86 , -10.76 ) , c64:: new( -0.69 , 4.70 ) , c64:: new( -0.69 , -4.70 ) , c64:: new( -10.46 , 0.00 ) ] ) ,
15
+ 1.0e-3 ) ;
16
+
17
+ /*
18
+ let answer = &arr2(&[[c64::new( 0.11, 0.17), c64::new( 0.11, -0.17), c64::new( 0.73, 0.00), c64::new( 0.73, 0.00), c64::new( 0.46, 0.00)],
19
+ [c64::new( 0.41, -0.26), c64::new( 0.41, 0.26), c64::new( -0.03, -0.02), c64::new( -0.03, 0.02), c64::new( 0.34, 0.00)],
20
+ [c64::new( 0.10, -0.51), c64::new( 0.10, 0.51), c64::new( 0.19, -0.29), c64::new( 0.19, 0.29), c64::new( 0.31, 0.00)],
21
+ [c64::new( 0.40, -0.09), c64::new( 0.40, 0.09), c64::new( -0.08, -0.08), c64::new( -0.08, 0.08), c64::new( -0.74, 0.00)],
22
+ [c64::new( 0.54, 0.00), c64::new( 0.54, 0.00), c64::new( -0.29, -0.49), c64::new( -0.29, 0.49), c64::new( 0.16, 0.00)]]);
23
+ */
24
+
25
+ let a_c: Array2 < c64 > = a. map ( |f| c64:: new ( * f, 0.0 ) ) ;
26
+ for ( i, v) in vecs. axis_iter ( Axis ( 1 ) ) . enumerate ( ) {
27
+ let av = a_c. dot ( & v) ;
28
+ let ev = v. mapv ( |f| e[ i] * f) ;
29
+ assert_close_l2 ! ( & av, & ev, 1.0e-7 ) ;
30
+ }
31
+ }
32
+
33
+ #[ test]
34
+ fn fgeev ( ) {
35
+ // https://software.intel.com/sites/products/documentation/doclib/mkl_sa/11/mkl_lapack_examples/dgeev_ex.f.htm
36
+ let a: Array2 < f32 > = arr2 ( & [ [ -1.01 , 0.86 , -4.60 , 3.31 , -4.81 ] ,
37
+ [ 3.98 , 0.53 , -7.04 , 5.29 , 3.55 ] ,
38
+ [ 3.30 , 8.26 , -3.89 , 8.20 , -1.51 ] ,
39
+ [ 4.43 , 4.96 , -7.66 , -7.33 , 6.18 ] ,
40
+ [ 7.31 , -6.43 , -6.16 , 2.47 , 5.58 ] ] ) ;
41
+ let ( e, vecs) : ( Array1 < _ > , Array2 < _ > ) = ( & a) . eig ( ) . unwrap ( ) ;
42
+ assert_close_l2 ! ( & e,
43
+ & arr1( & [ c32:: new( 2.86 , 10.76 ) , c32:: new( 2.86 , -10.76 ) , c32:: new( -0.69 , 4.70 ) , c32:: new( -0.69 , -4.70 ) , c32:: new( -10.46 , 0.00 ) ] ) ,
44
+ 1.0e-3 ) ;
45
+
46
+ /*
47
+ let answer = &arr2(&[[c32::new( 0.11, 0.17), c32::new( 0.11, -0.17), c32::new( 0.73, 0.00), c32::new( 0.73, 0.00), c32::new( 0.46, 0.00)],
48
+ [c32::new( 0.41, -0.26), c32::new( 0.41, 0.26), c32::new( -0.03, -0.02), c32::new( -0.03, 0.02), c32::new( 0.34, 0.00)],
49
+ [c32::new( 0.10, -0.51), c32::new( 0.10, 0.51), c32::new( 0.19, -0.29), c32::new( 0.19, 0.29), c32::new( 0.31, 0.00)],
50
+ [c32::new( 0.40, -0.09), c32::new( 0.40, 0.09), c32::new( -0.08, -0.08), c32::new( -0.08, 0.08), c32::new( -0.74, 0.00)],
51
+ [c32::new( 0.54, 0.00), c32::new( 0.54, 0.00), c32::new( -0.29, -0.49), c32::new( -0.29, 0.49), c32::new( 0.16, 0.00)]]);
52
+ */
53
+
54
+ let a_c: Array2 < c32 > = a. map ( |f| c32:: new ( * f, 0.0 ) ) ;
55
+ for ( i, v) in vecs. axis_iter ( Axis ( 1 ) ) . enumerate ( ) {
56
+ let av = a_c. dot ( & v) ;
57
+ let ev = v. mapv ( |f| e[ i] * f) ;
58
+ assert_close_l2 ! ( & av, & ev, 1.0e-5 ) ;
59
+ }
60
+ }
61
+
62
+ #[ test]
63
+ fn zgeev ( ) {
64
+ // https://software.intel.com/sites/products/documentation/doclib/mkl_sa/11/mkl_lapack_examples/zgeev_ex.f.htm
65
+ let a: Array2 < c64 > = arr2 ( & [ [ c64:: new ( -3.84 , 2.25 ) , c64:: new ( -8.94 , -4.75 ) , c64:: new ( 8.95 , -6.53 ) , c64:: new ( -9.87 , 4.82 ) ] ,
66
+ [ c64:: new ( -0.66 , 0.83 ) , c64:: new ( -4.40 , -3.82 ) , c64:: new ( -3.50 , -4.26 ) , c64:: new ( -3.15 , 7.36 ) ] ,
67
+ [ c64:: new ( -3.99 , -4.73 ) , c64:: new ( -5.88 , -6.60 ) , c64:: new ( -3.36 , -0.40 ) , c64:: new ( -0.75 , 5.23 ) ] ,
68
+ [ c64:: new ( 7.74 , 4.18 ) , c64:: new ( 3.66 , -7.53 ) , c64:: new ( 2.58 , 3.60 ) , c64:: new ( 4.59 , 5.41 ) ] , ] ) ;
69
+ let ( e, vecs) : ( Array1 < _ > , Array2 < _ > ) = ( & a) . eig ( ) . unwrap ( ) ;
70
+ assert_close_l2 ! ( & e,
71
+ & arr1( & [ c64:: new( -9.43 , -12.98 ) , c64:: new( -3.44 , 12.69 ) , c64:: new( 0.11 , -3.40 ) , c64:: new( 5.76 , 7.13 ) ] ) ,
72
+ 1.0e-3 ) ;
73
+
74
+ /*
75
+ let answer = &arr2(&[[c64::new( 0.43, 0.33), c64::new( 0.83, 0.00), c64::new( 0.60, 0.00), c64::new( -0.31, 0.03)],
76
+ [c64::new( 0.51, -0.03), c64::new( 0.08, -0.25), c64::new( -0.40, -0.20), c64::new( 0.04, 0.34)],
77
+ [c64::new( 0.62, 0.00), c64::new( -0.25, 0.28), c64::new( -0.09, -0.48), c64::new( 0.36, 0.06)],
78
+ [c64::new( -0.23, 0.11), c64::new( -0.10, -0.32), c64::new( -0.43, 0.13), c64::new( 0.81, 0.00)]]);
79
+ */
80
+
81
+ for ( i, v) in vecs. axis_iter ( Axis ( 1 ) ) . enumerate ( ) {
82
+ let av = a. dot ( & v) ;
83
+ let ev = v. mapv ( |f| e[ i] * f) ;
84
+ assert_close_l2 ! ( & av, & ev, 1.0e-7 ) ;
85
+ }
86
+ }
87
+
88
+ #[ test]
89
+ fn cgeev ( ) {
90
+ // https://software.intel.com/sites/products/documentation/doclib/mkl_sa/11/mkl_lapack_examples/zgeev_ex.f.htm
91
+ let a: Array2 < c32 > = arr2 ( & [ [ c32:: new ( -3.84 , 2.25 ) , c32:: new ( -8.94 , -4.75 ) , c32:: new ( 8.95 , -6.53 ) , c32:: new ( -9.87 , 4.82 ) ] ,
92
+ [ c32:: new ( -0.66 , 0.83 ) , c32:: new ( -4.40 , -3.82 ) , c32:: new ( -3.50 , -4.26 ) , c32:: new ( -3.15 , 7.36 ) ] ,
93
+ [ c32:: new ( -3.99 , -4.73 ) , c32:: new ( -5.88 , -6.60 ) , c32:: new ( -3.36 , -0.40 ) , c32:: new ( -0.75 , 5.23 ) ] ,
94
+ [ c32:: new ( 7.74 , 4.18 ) , c32:: new ( 3.66 , -7.53 ) , c32:: new ( 2.58 , 3.60 ) , c32:: new ( 4.59 , 5.41 ) ] , ] ) ;
95
+ let ( e, vecs) : ( Array1 < _ > , Array2 < _ > ) = ( & a) . eig ( ) . unwrap ( ) ;
96
+ assert_close_l2 ! ( & e,
97
+ & arr1( & [ c32:: new( -9.43 , -12.98 ) , c32:: new( -3.44 , 12.69 ) , c32:: new( 0.11 , -3.40 ) , c32:: new( 5.76 , 7.13 ) ] ) ,
98
+ 1.0e-3 ) ;
99
+
100
+ /*
101
+ let answer = &arr2(&[[c32::new( 0.43, 0.33), c32::new( 0.83, 0.00), c32::new( 0.60, 0.00), c32::new( -0.31, 0.03)],
102
+ [c32::new( 0.51, -0.03), c32::new( 0.08, -0.25), c32::new( -0.40, -0.20), c32::new( 0.04, 0.34)],
103
+ [c32::new( 0.62, 0.00), c32::new( -0.25, 0.28), c32::new( -0.09, -0.48), c32::new( 0.36, 0.06)],
104
+ [c32::new( -0.23, 0.11), c32::new( -0.10, -0.32), c32::new( -0.43, 0.13), c32::new( 0.81, 0.00)]]);
105
+ */
106
+
107
+ for ( i, v) in vecs. axis_iter ( Axis ( 1 ) ) . enumerate ( ) {
108
+ let av = a. dot ( & v) ;
109
+ let ev = v. mapv ( |f| e[ i] * f) ;
110
+ assert_close_l2 ! ( & av, & ev, 1.0e-5 ) ;
111
+ }
112
+ }
0 commit comments