1 /*
2 Copyright (C) 2014 Alex J. Best
3
4 This file is part of FLINT.
5
6 FLINT is free software: you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License (LGPL) as published
8 by the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version. See <https://www.gnu.org/licenses/>.
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <gmp.h>
15 #include "flint.h"
16 #include "fmpz.h"
17 #include "fmpz_mat.h"
18
19 int
main(void)20 main(void)
21 {
22 slong iter;
23 FLINT_TEST_INIT(state);
24
25 flint_printf("snf_kannan_bachem....");
26 fflush(stdout);
27
28 for (iter = 0; iter < 10000 * flint_test_multiplier(); iter++)
29 {
30 fmpz_mat_t A, S, S2;
31 slong m, n, b, d, r;
32 int equal;
33
34 m = n_randint(state, 10);
35 n = n_randint(state, 10);
36 r = n_randint(state, FLINT_MIN(m, n) + 1);
37
38 fmpz_mat_init(A, m, n);
39 fmpz_mat_init(S, m, n);
40 fmpz_mat_init(S2, m, n);
41
42 /* sparse */
43 b = 1 + n_randint(state, 10) * n_randint(state, 10);
44 d = n_randint(state, 2*m*n + 1);
45 fmpz_mat_randrank(A, state, r, b);
46
47 /* dense */
48 if (n_randint(state, 2))
49 fmpz_mat_randops(A, state, d);
50
51 fmpz_mat_snf_kannan_bachem(S, A);
52
53 if (!fmpz_mat_is_in_snf(S))
54 {
55 flint_printf("FAIL:\n");
56 flint_printf("matrix not in snf!\n");
57 fmpz_mat_print_pretty(A); flint_printf("\n\n");
58 fmpz_mat_print_pretty(S); flint_printf("\n\n");
59 abort();
60 }
61
62 fmpz_mat_snf_kannan_bachem(S2, S);
63 equal = fmpz_mat_equal(S, S2);
64
65 if (!equal)
66 {
67 flint_printf("FAIL:\n");
68 flint_printf("snf of a matrix in snf should be the same!\n");
69 fmpz_mat_print_pretty(A); flint_printf("\n\n");
70 fmpz_mat_print_pretty(S); flint_printf("\n\n");
71 fmpz_mat_print_pretty(S2); flint_printf("\n\n");
72 abort();
73 }
74
75 fmpz_mat_clear(S2);
76 fmpz_mat_clear(S);
77 fmpz_mat_clear(A);
78 }
79
80 FLINT_TEST_CLEANUP(state);
81
82 flint_printf("PASS\n");
83 return 0;
84 }
85
86