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, skip = 3;
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     which.pos = IGRAPH_EIGEN_SELECT;
52     which.il = skip;
53     which.iu = nodes - skip;
54 
55     igraph_vector_complex_init(&values, 0);
56     igraph_matrix_complex_init(&vectors, 0, 0);
57     igraph_eigen_matrix(&mat2, /*sparsemat=*/ 0, /*fun=*/ 0, nodes,
58                         /*extra=*/ 0, IGRAPH_EIGEN_LAPACK, &which,
59                         /*options=*/ 0, /*storage=*/ 0, &values, &vectors);
60 
61     which.pos = IGRAPH_EIGEN_ALL;
62 
63     igraph_vector_complex_init(&values2, 0);
64     igraph_matrix_complex_init(&vectors2, 0, 0);
65     igraph_eigen_matrix(&mat2, /*sparsemat=*/ 0, /*fun=*/ 0, nodes,
66                         /*extra=*/ 0, IGRAPH_EIGEN_LAPACK, &which,
67                         /*options=*/ 0, /*storage=*/ 0, &values2, &vectors2);
68 
69     for (i = 0; i < nodes - skip * 2 + 1; i++) {
70         int j;
71         igraph_real_t d =
72             igraph_complex_abs(igraph_complex_sub(VECTOR(values)[i],
73                                VECTOR(values2)[i + skip - 1]));
74         if (d > 1e-15) {
75             DUMP();
76             return 2;
77         }
78         for (j = 0; j < nodes; j++) {
79             igraph_real_t d =
80                 igraph_complex_abs(igraph_complex_sub(MATRIX(vectors, j, i),
81                                    MATRIX(vectors2, j, i + skip - 1)));
82             if (d > 1e-15) {
83                 DUMP();
84                 return 3;
85             }
86         }
87     }
88 
89     igraph_vector_complex_destroy(&values);
90     igraph_matrix_complex_destroy(&vectors);
91     igraph_vector_complex_destroy(&values2);
92     igraph_matrix_complex_destroy(&vectors2);
93     igraph_matrix_destroy(&mat2);
94 
95     VERIFY_FINALLY_STACK();
96 
97     return 0;
98 }
99