1 /*
2     Copyright (C) 2018 Martin Raum
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_mat.h"
18 
19 int
main(void)20 main(void)
21 {
22     int r, result;
23     fmpz_mat_t A, B, C;
24     fmpz_mat_t window1, window2;
25     slong m, n, k, l, i, j;
26     slong bits;
27 
28     FLINT_TEST_INIT(state);
29 
30     flint_printf("kronecker_product....");
31     fflush(stdout);
32 
33     for (r = 0; r < 100 * flint_test_multiplier(); r++)
34     {
35         m = n_randint(state, 10);
36         n = n_randint(state, 10);
37         k = n_randint(state, 10);
38         l = n_randint(state, 10);
39         if ( m && n )
40         {
41             i = n_randint(state, m);
42             j = n_randint(state, n);
43         }
44 
45         fmpz_mat_init(A, m, n);
46         fmpz_mat_init(B, k, l);
47         fmpz_mat_init(C, m*k, n*l);
48 
49         bits = 1 + n_randint(state, 100);
50 
51         fmpz_mat_randtest(A, state, bits);
52         fmpz_mat_randtest(B, state, bits);
53 
54         fmpz_mat_kronecker_product(C, A, B);
55 
56         if ( m && n )
57         {
58             fmpz_mat_window_init(window1, C, 0, 0, k, l);
59             fmpz_mat_window_init(window2, C, i*k, j*l, (i+1)*k, (j+1)*l);
60 
61             fmpz_mat_scalar_mul_fmpz(window1, window1, fmpz_mat_entry(A, i, j));
62             fmpz_mat_scalar_mul_fmpz(window2, window2, fmpz_mat_entry(A, 0, 0));
63 
64             result = fmpz_mat_equal(window1, window2);
65             if (!result)
66             {
67                 flint_printf("FAIL:\n");
68                 flint_printf("A:\n");
69                 fmpz_mat_print(A);
70                 flint_printf("B:\n");
71                 fmpz_mat_print(B);
72                 flint_printf("C:\n");
73                 fmpz_mat_print(C);
74                 flint_printf("i,j: %d,%d\n", i, j);
75                 abort();
76             }
77 
78             fmpz_mat_window_clear(window1);
79             fmpz_mat_window_clear(window2);
80         }
81 
82         fmpz_mat_clear(A);
83         fmpz_mat_clear(B);
84         fmpz_mat_clear(C);
85     }
86 
87     FLINT_TEST_CLEANUP(state);
88 
89     flint_printf("PASS\n");
90     return EXIT_SUCCESS;
91 }
92