1 /*
2 Copyright (C) 2011 Fredrik Johansson
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 <http://www.gnu.org/licenses/>.
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <gmp.h>
15 #include "flint.h"
16 #include "fmpq.h"
17 #include "fmpq_mat.h"
18
19 int
main(void)20 main(void)
21 {
22 int i;
23 FLINT_TEST_INIT(state);
24
25
26 flint_printf("rref....");
27 fflush(stdout);
28
29 for (i = 0; i < 1000 * flint_test_multiplier(); i++)
30 {
31 slong m, n, r, rank, b, d;
32 fmpq_mat_t A, B, C;
33 fmpz_mat_t M;
34 fmpz_t den;
35
36 m = n_randint(state, 10);
37 n = n_randint(state, 10);
38
39 fmpz_init(den);
40
41 for (r = 0; r <= FLINT_MIN(m,n); r++)
42 {
43 b = 1 + n_randint(state, 10) * n_randint(state, 10);
44 d = n_randint(state, 2*m*n + 1);
45
46 fmpz_mat_init(M, m, n);
47 fmpq_mat_init(A, m, n);
48 fmpq_mat_init(B, m, n);
49 fmpq_mat_init(C, m, n);
50
51 fmpz_mat_randrank(M, state, r, b);
52
53 if (i % 2 == 0)
54 fmpz_mat_randops(M, state, d);
55
56 fmpz_randtest_not_zero(den, state, b);
57 fmpq_mat_set_fmpz_mat_div_fmpz(A, M, den);
58
59 rank = fmpq_mat_rref_classical(B, A);
60 if (r != rank)
61 {
62 flint_printf("FAIL:\n");
63 flint_printf("fmpq_mat_rref_classical: wrong rank!\n");
64 fmpq_mat_print(A);
65 flint_printf("\nrank: %wd computed: %wd\n", r, rank);
66 abort();
67 }
68
69 rank = fmpq_mat_rref_fraction_free(C, A);
70 if (r != rank)
71 {
72 flint_printf("FAIL:\n");
73 flint_printf("fmpq_mat_rref_fraction_free: wrong rank!\n");
74 abort();
75 }
76
77 if (!fmpq_mat_equal(B, C))
78 {
79 flint_printf("FAIL:\n");
80 flint_printf("different results!\n");
81 flint_printf("A:\n");
82 fmpq_mat_print(A);
83 flint_printf("\nB:\n");
84 fmpq_mat_print(B);
85 flint_printf("\nC:\n");
86 fmpq_mat_print(C);
87 abort();
88 }
89
90 fmpz_mat_clear(M);
91 fmpq_mat_clear(A);
92 fmpq_mat_clear(B);
93 fmpq_mat_clear(C);
94 }
95
96 fmpz_clear(den);
97 }
98
99 FLINT_TEST_CLEANUP(state);
100
101 flint_printf("PASS\n");
102 return 0;
103 }
104