1 /*
2 Copyright (C) 2021 Daniel Schultz
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
main(void)21 int main(void)
22 {
23 fmpz_mat_t A, B, C, D;
24 slong i;
25 slong max_threads = 6;
26 FLINT_TEST_INIT(state);
27
28 flint_printf("mul_small....");
29 fflush(stdout);
30
31 for (i = 0; i < 100 * flint_test_multiplier(); i++)
32 {
33 slong m, k, n;
34
35 if (flint_get_num_threads() >= max_threads - 1)
36 {
37 m = n_randint(state, 200);
38 n = n_randint(state, 200);
39 k = n_randint(state, 200);
40 }
41 else
42 {
43 m = n_randint(state, 50);
44 n = n_randint(state, 50);
45 k = n_randint(state, 50);
46 }
47
48 fmpz_mat_init(A, m, k);
49 fmpz_mat_init(B, k, n);
50 fmpz_mat_init(C, m, n);
51 fmpz_mat_init(D, m, n);
52
53 fmpz_mat_randtest(A, state, n_randint(state, FLINT_BITS - 2) + 1);
54 fmpz_mat_randtest(B, state, n_randint(state, FLINT_BITS - 2) + 1);
55 fmpz_mat_randtest(C, state, n_randint(state, 200) + 1);
56 fmpz_mat_randtest(D, state, n_randint(state, 200) + 1);
57
58 _fmpz_mat_mul_small(C, A, B);
59 fmpz_mat_mul_classical_inline(D, A, B);
60
61 if (!fmpz_mat_equal(C, D))
62 {
63 flint_printf("FAIL: results not equal\n\n");
64 fmpz_mat_print(A); flint_printf("\n\n");
65 fmpz_mat_print(B); flint_printf("\n\n");
66 fmpz_mat_print(C); flint_printf("\n\n");
67 fmpz_mat_print(D); flint_printf("\n\n");
68 flint_abort();
69 }
70
71 flint_set_num_threads(n_randint(state, max_threads) + 1);
72
73 fmpz_mat_clear(A);
74 fmpz_mat_clear(B);
75 fmpz_mat_clear(C);
76 fmpz_mat_clear(D);
77 }
78
79 FLINT_TEST_CLEANUP(state);
80
81 flint_printf("PASS\n");
82 return 0;
83 }
84