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.h"
16 #include "fmpz_mat.h"
17 #include "fmpz_poly.h"
18 #include "fmpz_poly_mat.h"
19 
20 int
main(void)21 main(void)
22 {
23     slong i;
24 
25     FLINT_TEST_INIT(state);
26 
27     flint_printf("prod....");
28     fflush(stdout);
29 
30     for (i = 0; i < 50 * flint_test_multiplier(); i++)
31     {
32         fmpz_poly_mat_t A, B, *V;
33         slong m, j, count, bits, deg;
34         float density;
35 
36         m = n_randint(state, 6);
37         deg = 1 + n_randint(state, 6);
38         bits = 1 + n_randint(state, 100);
39         count = n_randint(state, 20);
40         density = n_randint(state, 100) * 0.01;
41 
42         fmpz_poly_mat_init(A, m, m);
43         fmpz_poly_mat_init(B, m, m);
44 
45         V = flint_malloc(sizeof(fmpz_poly_mat_t) * count);
46         for (j = 0; j < count; j++)
47         {
48             fmpz_poly_mat_init(V[j], m, m);
49             fmpz_poly_mat_randtest_sparse(V[j], state, deg, bits, density);
50         }
51 
52         fmpz_poly_mat_prod(A, V, count);
53 
54         fmpz_poly_mat_one(B);
55         for (j = 0; j < count; j++)
56             fmpz_poly_mat_mul(B, B, V[j]);
57 
58         if (!fmpz_poly_mat_equal(A, B))
59         {
60             flint_printf("FAIL:\n");
61             flint_printf("count = %wd\n", count);
62             flint_printf("A:\n");
63             fmpz_poly_mat_print(A, "x");
64             flint_printf("B:\n");
65             fmpz_poly_mat_print(B, "x");
66             abort();
67         }
68 
69         fmpz_poly_mat_clear(A);
70         fmpz_poly_mat_clear(B);
71         for (j = 0; j < count; j++)
72             fmpz_poly_mat_clear(V[j]);
73         flint_free(V);
74     }
75 
76     FLINT_TEST_CLEANUP(state);
77 
78     flint_printf("PASS\n");
79     return 0;
80 }
81