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 <http://www.gnu.org/licenses/>.
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include "flint.h"
15 #include "fmpz_poly.h"
16 #include "fmpz_poly_mat.h"
17
18
19 int
main(void)20 main(void)
21 {
22 slong i;
23
24 FLINT_TEST_INIT(state);
25
26 flint_printf("sqr_KS....");
27 fflush(stdout);
28
29 for (i = 0; i < 200 * flint_test_multiplier(); i++)
30 {
31 fmpz_poly_mat_t A, C, D;
32 slong m, bits, deg;
33
34 /* TODO: add separate unsigned tests */
35 m = n_randint(state, 15);
36 deg = 1 + n_randint(state, 15);
37 bits = 1 + n_randint(state, 150);
38
39 fmpz_poly_mat_init(A, m, m);
40 fmpz_poly_mat_init(C, m, m);
41 fmpz_poly_mat_init(D, m, m);
42
43 if (n_randint(state, 2))
44 fmpz_poly_mat_randtest(A, state, deg, bits);
45 else
46 fmpz_poly_mat_randtest(A, state, deg, bits);
47 fmpz_poly_mat_randtest(C, state, deg, bits); /* noise in output */
48
49 fmpz_poly_mat_sqr_classical(C, A);
50 fmpz_poly_mat_sqr_KS(D, A);
51
52 if (!fmpz_poly_mat_equal(C, D))
53 {
54 flint_printf("FAIL:\n");
55 flint_printf("products don't agree!\n");
56 flint_printf("A:\n");
57 fmpz_poly_mat_print(A, "x");
58 flint_printf("B:\n");
59 fmpz_poly_mat_print(C, "x");
60 flint_printf("D:\n");
61 fmpz_poly_mat_print(D, "x");
62 flint_printf("\n");
63 abort();
64 }
65
66 fmpz_poly_mat_clear(A);
67 fmpz_poly_mat_clear(C);
68 fmpz_poly_mat_clear(D);
69 }
70
71 /* Check aliasing B and A */
72 for (i = 0; i < 10 * flint_test_multiplier(); i++)
73 {
74 fmpz_poly_mat_t A, B;
75 slong m, bits, deg;
76
77 m = n_randint(state, 20);
78 deg = 1 + n_randint(state, 10);
79 bits = 1 + n_randint(state, 100);
80
81 fmpz_poly_mat_init(A, m, m);
82 fmpz_poly_mat_init(B, m, m);
83
84 fmpz_poly_mat_randtest(A, state, deg, bits);
85 fmpz_poly_mat_randtest(B, state, deg, bits);
86
87 fmpz_poly_mat_sqr_KS(B, A);
88 fmpz_poly_mat_sqr_KS(A, A);
89
90 if (!fmpz_poly_mat_equal(B, A))
91 {
92 flint_printf("FAIL (aliasing):\n");
93 flint_printf("A:\n");
94 fmpz_poly_mat_print(A, "x");
95 flint_printf("B:\n");
96 fmpz_poly_mat_print(B, "x");
97 flint_printf("\n");
98 abort();
99 }
100
101 fmpz_poly_mat_clear(A);
102 fmpz_poly_mat_clear(B);
103 }
104
105 FLINT_TEST_CLEANUP(state);
106
107 flint_printf("PASS\n");
108 return 0;
109 }
110