1 /*
2 IGraph library.
3 Copyright (C) 2021 The igraph development team <igraph@igraph.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19 #include <igraph.h>
20 #include "test_utilities.inc"
21
print_and_destroy(igraph_matrix_t * vectors,igraph_matrix_t * values,int nev,igraph_error_type_t error)22 void print_and_destroy(igraph_matrix_t *vectors, igraph_matrix_t *values, int nev, igraph_error_type_t error) {
23 printf("vectors in:\n");
24 print_matrix_format(vectors, stdout, "%6.2f");
25 printf("values in:\n");
26 print_matrix_format(values, stdout, "%6.2f");
27 IGRAPH_ASSERT(igraph_arpack_unpack_complex(vectors, values, nev) == (int)error);
28 printf("vectors out:\n");
29 print_matrix_format(vectors, stdout, "%6.2f");
30 printf("values out:\n");
31 print_matrix_format(values, stdout, "%6.2f");
32 igraph_matrix_destroy(vectors);
33 igraph_matrix_destroy(values);
34 printf("\n");
35 }
36
main()37 int main() {
38 igraph_matrix_t vectors;
39 igraph_matrix_t values;
40
41 printf("Empty vectors and values:\n");
42 matrix_init_int_row_major(&vectors, 0, 0, NULL);
43 matrix_init_int_row_major(&values, 0, 0, NULL);
44 print_and_destroy(&vectors, &values, 0, IGRAPH_SUCCESS);
45
46 {
47 printf("Real vectors and values:\n");
48 int vectors_elem[4] = {-1, 0, 9, 10};
49 int values_elem[4] = {-6, 0, 3, 0};
50 matrix_init_int_row_major(&vectors, 2, 2, vectors_elem);
51 matrix_init_int_row_major(&values, 2, 2, values_elem);
52 print_and_destroy(&vectors, &values, 2, IGRAPH_SUCCESS);
53 }
54 {
55 printf("Complex vectors and values:\n");
56 igraph_real_t vectors_elem[36] = {
57 0.123938, 0.3411, 0.114301, -0.134822, -0.421672, -0.484969,
58 -0.268889, 0.00766665, 0.413844, 0.200565, -0.0336028, -0.133362,
59 -0.192782, -0.140134, 0.579782, -0.0853149, -0.0684855, 0.117105,
60 0.175547, 0.1833, 0.156218, 0.0623488, 0.422265, -0.257261,
61 -0.266691, 0.404647, -0.462498, -0.0885737, 0.203893, -0.135195,
62 0.662813, -0.022972, -0.193704, 0.355354, -0.0405741, 0.493652};
63 igraph_real_t values_elem[12] = {
64 -2.58338, 9.66092, -2.58338, -9.66092, 7.07998, 6.51033,
65 7.07998, -6.51033, -7.9966, 2.74368, -7.9966, -2.74368};
66 matrix_init_real_row_major(&vectors, 6, 6, vectors_elem);
67 matrix_init_real_row_major(&values, 6, 2, values_elem);
68 print_and_destroy(&vectors, &values, 6, IGRAPH_SUCCESS);
69 }
70 {
71 printf("Both complex and real vectors and values:\n");
72 int vectors_elem[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
73 int values_elem[8] = {1, 0, 2, 1, 2, -1, 3, 0};
74 matrix_init_int_row_major(&vectors, 4, 4, vectors_elem);
75 matrix_init_int_row_major(&values, 4, 2, values_elem);
76 print_and_destroy(&vectors, &values, 4, IGRAPH_SUCCESS);
77 }
78 {
79 printf("Both complex and real vectors and values, but nev = 2:\n");
80 int vectors_elem[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
81 int values_elem[8] = {1, 0, 2, 1, 2, -1, 3, 0};
82 matrix_init_int_row_major(&vectors, 4, 4, vectors_elem);
83 matrix_init_int_row_major(&values, 4, 2, values_elem);
84 print_and_destroy(&vectors, &values, 2, IGRAPH_SUCCESS);
85 }
86 {
87 printf("No vectors but there are values:\n");
88 int values_elem[8] = {1, 0, 2, 1, 2, -1, 3, 0};
89 matrix_init_int_row_major(&vectors, 0, 0, NULL);
90 matrix_init_int_row_major(&values, 4, 2, values_elem);
91 print_and_destroy(&vectors, &values, 4, IGRAPH_SUCCESS);
92 }
93 {
94 printf("No values, but there are vectors:\n");
95 int vectors_elem[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
96 matrix_init_int_row_major(&vectors, 4, 4, vectors_elem);
97 matrix_init_int_row_major(&values, 0, 0, NULL);
98 print_and_destroy(&vectors, &values, 0, IGRAPH_SUCCESS);
99 }
100
101 VERIFY_FINALLY_STACK();
102 return 0;
103 }
104