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
check_and_destroy(igraph_matrix_t * matrix,igraph_bool_t pivot)22 void check_and_destroy(igraph_matrix_t *matrix, igraph_bool_t pivot) {
23 igraph_vector_int_t pivot_indices;
24 int info;
25 igraph_vector_int_init(&pivot_indices, 0);
26 printf("Starting matrix:\n");
27 igraph_matrix_print(matrix);
28 if (pivot) {
29 IGRAPH_ASSERT(igraph_lapack_dgetrf(matrix, &pivot_indices, &info) == IGRAPH_SUCCESS);
30 } else {
31 IGRAPH_ASSERT(igraph_lapack_dgetrf(matrix, NULL, &info) == IGRAPH_SUCCESS);
32 }
33 printf("Returned matrix:\n");
34 igraph_matrix_print(matrix);
35 if (pivot) {
36 printf("Returned pivot indices:\n");
37 igraph_vector_int_print(&pivot_indices);
38 }
39 printf("info: %d\n", info);
40 igraph_vector_int_destroy(&pivot_indices);
41 igraph_matrix_destroy(matrix);
42 printf("\n");
43 }
44
main()45 int main() {
46 igraph_matrix_t matrix;
47
48 printf("Empty matrix:\n");
49 igraph_matrix_init(&matrix, 0, 0);
50 check_and_destroy(&matrix, 1);
51
52 int elements_1[9] = {7, 8, 9, 2, 2, 3, 1, 1, 1};
53 matrix_init_int_row_major(&matrix, 3, 3, elements_1);
54 check_and_destroy(&matrix, 1);
55
56 int elements_2[9] = {1, 1, 1, 2, 2, 3, 7, 8, 9};
57 matrix_init_int_row_major(&matrix, 3, 3, elements_2);
58 check_and_destroy(&matrix, 1);
59
60 int elements_3[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
61 matrix_init_int_row_major(&matrix, 3, 3, elements_3);
62 check_and_destroy(&matrix, 0);
63
64 int elements_4[6] = {1, 2, 3, 4, 5, 6};
65 matrix_init_int_row_major(&matrix, 2, 3, elements_4);
66 check_and_destroy(&matrix, 1);
67
68 int elements_5[6] = {1, 2, 3, 4, 5, 6};
69 matrix_init_int_row_major(&matrix, 3, 2, elements_5);
70 check_and_destroy(&matrix, 1);
71
72 VERIFY_FINALLY_STACK();
73 return 0;
74 }
75