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 <https://www.gnu.org/licenses/>.
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include "flint.h"
15 #include "fmpz_mat.h"
16 #include "fmpz_poly.h"
17 #include "fmpz_poly_mat.h"
18
19
20 int
main(void)21 main(void)
22 {
23 slong i;
24
25 FLINT_TEST_INIT(state);
26
27 flint_printf("rank....");
28 fflush(stdout);
29
30 for (i = 0; i < 100 * flint_test_multiplier(); i++)
31 {
32 fmpz_poly_mat_t A;
33 fmpz_mat_t Ax;
34 fmpz_t x;
35 slong j, m, n, bits, deg, rank, zrank;
36 float density;
37
38 m = n_randint(state, 15);
39 n = n_randint(state, 15);
40 deg = 1 + n_randint(state, 5);
41 bits = 1 + n_randint(state, 100);
42 density = n_randint(state, 100) * 0.01;
43
44 fmpz_poly_mat_init(A, m, n);
45 fmpz_mat_init(Ax, m, n);
46 fmpz_init(x);
47
48 fmpz_poly_mat_randtest_sparse(A, state, deg, bits, density);
49
50 /* Probabilistic rank computation */
51 zrank = 0;
52 for (j = 0; j < 5; j++)
53 {
54 slong r;
55 fmpz_randbits(x, state, 15);
56 fmpz_poly_mat_evaluate_fmpz(Ax, A, x);
57 r = fmpz_mat_rank(Ax);
58 zrank = FLINT_MAX(zrank, r);
59 }
60
61 rank = fmpz_poly_mat_rank(A);
62
63 if (rank != zrank)
64 {
65 flint_printf("FAIL:\n");
66 flint_printf("A:\n");
67 fmpz_poly_mat_print(A, "x");
68 flint_printf("Computed rank: %wd (zrank = %wd)\n", rank, zrank);
69 abort();
70 }
71
72 fmpz_clear(x);
73 fmpz_mat_clear(Ax);
74 fmpz_poly_mat_clear(A);
75 }
76
77 FLINT_TEST_CLEANUP(state);
78
79 flint_printf("PASS\n");
80 return 0;
81 }
82