1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
Copyright (C) 2016 William Hart
This file is part of FLINT.
FLINT is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include "test_helpers.h"
#include "fmpz.h"
#include "fmpz_mat.h"
TEST_FUNCTION_START(fmpz_mat_col_partition, state)
{
int result = 0;
slong i;
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpz_mat_t A, B;
slong m, n, j, k, p1 = 1, p2;
slong * part;
m = n_randint(state, 20) + 1;
n = n_randint(state, 20) + 1;
part = (slong *) flint_malloc(m*sizeof(slong));
fmpz_mat_init(A, m, n);
fmpz_mat_init(B, n, m);
/* set first row */
for (j = 0; j < n; j++)
fmpz_randtest(fmpz_mat_entry(A, 0, j), state, 100);
/* ensure row is distinct */
fmpz_set_ui(fmpz_mat_entry(A, 0, n_randint(state, n)), 0);
/* fill remaining rows */
for (k = 1; k < m; k++)
{
if (n_randint(state, 2) == 0)
{
/* random row */
for (j = 0; j < n; j++)
fmpz_randtest(fmpz_mat_entry(A, k, j), state, 100);
/* ensure row is distinct */
fmpz_set_ui(fmpz_mat_entry(A, k, n_randint(state, n)), k);
p1++;
} else
{
/* same as last row */
for (j = 0; j < n; j++)
fmpz_set(fmpz_mat_entry(A, k, j), fmpz_mat_entry(A, k - 1, j));
}
}
/* swap random rows */
for (k = 0; k < m; k++)
{
slong r1 = n_randint(state, m);
slong r2 = n_randint(state, m);
fmpz_mat_swap_rows(A, NULL, r1, r2);
}
/* transpose so rows are now columns */
fmpz_mat_transpose(B, A);
/* check partition is correct */
p2 = fmpz_mat_col_partition(part, B, 1);
result = (p1 > n || p2 == p1);
if (!result)
{
flint_printf("FAIL: col_partition failed\n");
flint_printf("m = %ld, n = %ld, p1 = %ld, p2 = %ld\n", m, n, p1, p2);
fflush(stdout);
flint_abort();
}
fmpz_mat_clear(A);
fmpz_mat_clear(B);
flint_free(part);
}
TEST_FUNCTION_END(state);
}