1 /* -*- mode: C -*- */
2 /*
3 IGraph library.
4 Copyright (C) 2011-2012 Gabor Csardi <csardi.gabor@gmail.com>
5 334 Harvard st, Cambridge MA, 02139 USA
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA
21
22 */
23
24 #include <igraph.h>
25
26 #include "test_utilities.inc"
27
28 #define DUMP() do { \
29 igraph_vector_complex_print(&values); \
30 igraph_vector_complex_print(&values2); \
31 } while(0)
32
main()33 int main() {
34
35 const int nodes = 10;
36 igraph_matrix_t mat2;
37 igraph_vector_complex_t values, values2;
38 igraph_matrix_complex_t vectors, vectors2;
39 igraph_eigen_which_t which;
40 int i;
41
42 igraph_rng_seed(igraph_rng_default(), 42);
43 igraph_matrix_init(&mat2, nodes, nodes);
44 for (i = 0; i < nodes; i++) {
45 int j;
46 for (j = 0; j < nodes; j++) {
47 MATRIX(mat2, i, j) = igraph_rng_get_integer(igraph_rng_default(), 1, 10);
48 }
49 }
50
51 /* Test LR, a single eigenvalue first */
52
53 igraph_vector_complex_init(&values, 0);
54 igraph_matrix_complex_init(&vectors, 0, 0);
55 which.pos = IGRAPH_EIGEN_LR;
56 which.howmany = 1;
57
58 igraph_eigen_matrix(&mat2, /*sparsemat=*/ 0, /*fun=*/ 0, nodes,
59 /*extra=*/ 0, IGRAPH_EIGEN_LAPACK, &which,
60 /*options=*/ 0, /*storage=*/ 0, &values, &vectors);
61
62 igraph_vector_complex_print(&values);
63 igraph_matrix_complex_print(&vectors);
64
65 igraph_vector_complex_destroy(&values);
66 igraph_matrix_complex_destroy(&vectors);
67
68 /* LR, and SR, all eigenvalues */
69
70 igraph_vector_complex_init(&values, 0);
71 igraph_matrix_complex_init(&vectors, 0, 0);
72 which.pos = IGRAPH_EIGEN_LR;
73 which.howmany = nodes;
74 igraph_eigen_matrix(&mat2, /*sparsemat=*/ 0, /*fun=*/ 0, nodes,
75 /*extra=*/ 0, IGRAPH_EIGEN_LAPACK, &which,
76 /*options=*/ 0, /*storage=*/ 0, &values, &vectors);
77
78 igraph_vector_complex_init(&values2, 0);
79 igraph_matrix_complex_init(&vectors2, 0, 0);
80 which.pos = IGRAPH_EIGEN_SR;
81 which.howmany = nodes;
82 igraph_eigen_matrix(&mat2, /*sparsemat=*/ 0, /*fun=*/ 0, nodes,
83 /*extra=*/ 0, IGRAPH_EIGEN_LAPACK, &which,
84 /*options=*/ 0, /*storage=*/ 0, &values2, &vectors2);
85
86 for (i = 0; i < nodes; i++) {
87 int j;
88 igraph_real_t d =
89 igraph_complex_abs(igraph_complex_sub(VECTOR(values)[i],
90 VECTOR(values2)[nodes - i - 1]));
91 if (d > 1e-15) {
92 DUMP();
93 return 2;
94 }
95 for (j = 0; j < nodes; j++) {
96 igraph_real_t d =
97 igraph_complex_abs(igraph_complex_sub(MATRIX(vectors, j, i),
98 MATRIX(vectors2, j,
99 nodes - i - 1)));
100 if (d > 1e-15) {
101 DUMP();
102 return 3;
103 }
104 }
105 }
106
107 igraph_vector_complex_destroy(&values);
108 igraph_matrix_complex_destroy(&vectors);
109 igraph_vector_complex_destroy(&values2);
110 igraph_matrix_complex_destroy(&vectors2);
111
112 igraph_matrix_destroy(&mat2);
113
114 VERIFY_FINALLY_STACK();
115
116 return 0;
117 }
118