1 /*
2 Copyright (C) 2012 Sebastian Pancratz
3 Copyright (C) 2013 Mike Hansen
4
5 This file is part of FLINT.
6
7 FLINT is free software: you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License (LGPL) as published
9 by the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version. See <http://www.gnu.org/licenses/>.
11 */
12
13 #ifdef T
14
15 #include "templates.h"
16
17 #include <stdio.h>
18 #include <stdlib.h>
19
20 #include "ulong_extras.h"
21 #include "long_extras.h"
22
23 int
main(void)24 main(void)
25 {
26 int i, result;
27 FLINT_TEST_INIT(state);
28
29 flint_printf("compose_divconquer... ");
30 fflush(stdout);
31
32 /* Check aliasing of the first argument */
33 for (i = 0; i < 5 * flint_test_multiplier(); i++)
34 {
35 TEMPLATE(T, ctx_t) ctx;
36
37 TEMPLATE(T, poly_t) f, g, h;
38
39 TEMPLATE(T, ctx_randtest) (ctx, state);
40 TEMPLATE(T, poly_init) (f, ctx);
41 TEMPLATE(T, poly_init) (g, ctx);
42 TEMPLATE(T, poly_init) (h, ctx);
43
44 TEMPLATE(T, poly_randtest) (f, state, n_randint(state, 40), ctx);
45 TEMPLATE(T, poly_randtest) (g, state, n_randint(state, 20), ctx);
46
47 TEMPLATE(T, poly_compose_divconquer) (h, f, g, ctx);
48 TEMPLATE(T, poly_compose_divconquer) (f, f, g, ctx);
49
50 result = (TEMPLATE(T, poly_equal) (f, h, ctx));
51 if (!result)
52 {
53 flint_printf("FAIL:\n\n");
54 flint_printf("f = "), TEMPLATE(T, poly_print_pretty) (f, "X", ctx),
55 flint_printf("\n");
56 flint_printf("g = "), TEMPLATE(T, poly_print_pretty) (g, "X", ctx),
57 flint_printf("\n");
58 flint_printf("h = "), TEMPLATE(T, poly_print_pretty) (h, "X", ctx),
59 flint_printf("\n");
60 abort();
61 }
62
63 TEMPLATE(T, poly_clear) (f, ctx);
64 TEMPLATE(T, poly_clear) (g, ctx);
65 TEMPLATE(T, poly_clear) (h, ctx);
66
67 TEMPLATE(T, ctx_clear) (ctx);
68 }
69
70 /* Check aliasing of the second argument */
71 for (i = 0; i < 5 * flint_test_multiplier(); i++)
72 {
73 TEMPLATE(T, ctx_t) ctx;
74
75 TEMPLATE(T, poly_t) f, g, h;
76
77 TEMPLATE(T, ctx_randtest) (ctx, state);
78 TEMPLATE(T, poly_init) (f, ctx);
79 TEMPLATE(T, poly_init) (g, ctx);
80 TEMPLATE(T, poly_init) (h, ctx);
81
82 TEMPLATE(T, poly_randtest) (f, state, n_randint(state, 40), ctx);
83 TEMPLATE(T, poly_randtest) (g, state, n_randint(state, 20), ctx);
84
85 TEMPLATE(T, poly_compose_divconquer) (h, f, g, ctx);
86 TEMPLATE(T, poly_compose_divconquer) (g, f, g, ctx);
87
88 result = (TEMPLATE(T, poly_equal) (g, h, ctx));
89 if (!result)
90 {
91 flint_printf("FAIL:\n\n");
92 flint_printf("f = "), TEMPLATE(T, poly_print_pretty) (f, "X", ctx),
93 flint_printf("\n");
94 flint_printf("g = "), TEMPLATE(T, poly_print_pretty) (g, "X", ctx),
95 flint_printf("\n");
96 flint_printf("h = "), TEMPLATE(T, poly_print_pretty) (h, "X", ctx),
97 flint_printf("\n");
98 abort();
99 }
100
101 TEMPLATE(T, poly_clear) (f, ctx);
102 TEMPLATE(T, poly_clear) (g, ctx);
103 TEMPLATE(T, poly_clear) (h, ctx);
104
105 TEMPLATE(T, ctx_clear) (ctx);
106 }
107
108 /* Compare with the naive method */
109 for (i = 0; i < 5 * flint_test_multiplier(); i++)
110 {
111 TEMPLATE(T, ctx_t) ctx;
112
113 TEMPLATE(T, poly_t) f, g, h, s, t;
114 slong k;
115
116 TEMPLATE(T, ctx_randtest) (ctx, state);
117 TEMPLATE(T, poly_init) (f, ctx);
118 TEMPLATE(T, poly_init) (g, ctx);
119 TEMPLATE(T, poly_init) (h, ctx);
120 TEMPLATE(T, poly_init) (s, ctx);
121 TEMPLATE(T, poly_init) (t, ctx);
122
123 TEMPLATE(T, poly_randtest) (g, state, n_randint(state, 40), ctx);
124 TEMPLATE(T, poly_randtest) (h, state, n_randint(state, 20), ctx);
125
126 TEMPLATE(T, poly_one) (t, ctx);
127 for (k = 0; k < TEMPLATE(T, poly_length) (g, ctx); k++)
128 {
129 TEMPLATE(T, TEMPLATE(poly_scalar_addmul, T)) (s, t, g->coeffs + k,
130 ctx);
131 TEMPLATE(T, poly_mul) (t, t, h, ctx);
132 }
133
134 TEMPLATE(T, poly_compose_divconquer) (f, g, h, ctx);
135
136 result = (TEMPLATE(T, poly_equal) (f, s, ctx));
137 if (!result)
138 {
139 flint_printf("FAIL:\n\n");
140 flint_printf("f = "), TEMPLATE(T, poly_print_pretty) (f, "X", ctx),
141 flint_printf("\n");
142 flint_printf("g = "), TEMPLATE(T, poly_print_pretty) (g, "X", ctx),
143 flint_printf("\n");
144 flint_printf("h = "), TEMPLATE(T, poly_print_pretty) (h, "X", ctx),
145 flint_printf("\n");
146 flint_printf("s = "), TEMPLATE(T, poly_print_pretty) (s, "X", ctx),
147 flint_printf("\n");
148 flint_printf("t = "), TEMPLATE(T, poly_print_pretty) (t, "X", ctx),
149 flint_printf("\n");
150 abort();
151 }
152
153 TEMPLATE(T, poly_clear) (f, ctx);
154 TEMPLATE(T, poly_clear) (g, ctx);
155 TEMPLATE(T, poly_clear) (h, ctx);
156 TEMPLATE(T, poly_clear) (s, ctx);
157 TEMPLATE(T, poly_clear) (t, ctx);
158
159 TEMPLATE(T, ctx_clear) (ctx);
160 }
161
162 FLINT_TEST_CLEANUP(state);
163 flint_printf("PASS\n");
164 return EXIT_SUCCESS;
165 }
166
167
168
169 #endif
170