1 /*
2 Copyright (C) 2010 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 <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_vec.h"
18 #include "fmpz_mat.h"
19 #include "ulong_extras.h"
20
21
22 int
main(void)23 main(void)
24 {
25 fmpz_mat_t A;
26 slong i, m, n, b, d, r;
27
28 FLINT_TEST_INIT(state);
29
30 flint_printf("rank....");
31 fflush(stdout);
32
33 /* Maximally sparse matrices of given rank */
34 for (i = 0; i < 50 * flint_test_multiplier(); i++)
35 {
36 m = n_randint(state, 35);
37 n = n_randint(state, 35);
38
39 for (r = 0; r <= FLINT_MIN(m,n); r++)
40 {
41 b = 1 + n_randint(state, 10) * n_randint(state, 10);
42 d = n_randint(state, 2*m*n + 1);
43 fmpz_mat_init(A, m, n);
44 fmpz_mat_randrank(A, state, r, b);
45 if (r != fmpz_mat_rank(A))
46 {
47 flint_printf("FAIL:\n");
48 flint_printf("wrong rank!\n");
49 abort();
50 }
51 fmpz_mat_clear(A);
52 }
53 }
54
55 /* Dense */
56 for (i = 0; i < 50 * flint_test_multiplier(); i++)
57 {
58 m = n_randint(state, 35);
59 n = n_randint(state, 35);
60
61 for (r = 0; r <= FLINT_MIN(m,n); r++)
62 {
63 b = 1 + n_randint(state, 10) * n_randint(state, 10);
64 d = n_randint(state, 2*m*n + 1);
65 fmpz_mat_init(A, m, n);
66 fmpz_mat_randrank(A, state, r, b);
67 fmpz_mat_randops(A, state, d);
68 if (r != fmpz_mat_rank(A))
69 {
70 flint_printf("FAIL:\n");
71 flint_printf("wrong rank!\n");
72 abort();
73 }
74 fmpz_mat_clear(A);
75 }
76 }
77
78 FLINT_TEST_CLEANUP(state);
79
80 flint_printf("PASS\n");
81 return 0;
82 }
83