1 /*
2 Copyright (C) 2010,2011 Fredrik Johansson
3 Copyright (C) 2013 Mike Hansen
4 Copyright (C) 2018 Tommy Hofmann
5
6 This file is part of FLINT.
7
8 FLINT is free software: you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License (LGPL) as published
10 by the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version. See <http://www.gnu.org/licenses/>.
12 */
13
14 #ifdef T
15
16 #include "templates.h"
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <limits.h>
21
22 int
main(void)23 main(void)
24 {
25 TEMPLATE(T, ctx_t) ctx;
26 TEMPLATE(T, mat_t) A, X, B, AX;
27 slong i, m, n, r;
28 int solved;
29
30 FLINT_TEST_INIT(state);
31 printf("solve....");
32 fflush(stdout);
33
34 for (i = 0; i < 5 * flint_test_multiplier(); i++)
35 {
36 TEMPLATE(T, ctx_randtest) (ctx, state);
37
38 m = n_randint(state, 50);
39 n = n_randint(state, 50);
40
41 TEMPLATE(T, mat_init) (A, m, m, ctx);
42 TEMPLATE(T, mat_init) (B, m, n, ctx);
43 TEMPLATE(T, mat_init) (X, m, n, ctx);
44 TEMPLATE(T, mat_init) (AX, m, n, ctx);
45
46 TEMPLATE(T, mat_randrank)(A, state, m, ctx);
47 TEMPLATE(T, mat_randtest)(B, state, ctx);
48
49 /* Dense */
50 if (n_randint(state, 2))
51 TEMPLATE(T, mat_randops)(A, 1+n_randint(state, 1+m*m), state, ctx);
52
53 solved = TEMPLATE(T, mat_solve)(X, A, B, ctx);
54
55 TEMPLATE(T, mat_mul)(AX, A, X, ctx);
56
57 if (!TEMPLATE(T, mat_equal)(AX, B, ctx) || !solved)
58 {
59 flint_printf("FAIL:\n");
60 flint_printf("AX != B!\n");
61 flint_printf("A:\n");
62 TEMPLATE(T, mat_print_pretty)(A, ctx);
63 flint_printf("B:\n");
64 TEMPLATE(T, mat_print_pretty)(B, ctx);
65 flint_printf("X:\n");
66 TEMPLATE(T, mat_print_pretty)(X, ctx);
67 flint_printf("AX:\n");
68 TEMPLATE(T, mat_print_pretty)(AX, ctx);
69 flint_printf("\n");
70 abort();
71 }
72
73 TEMPLATE(T, mat_clear)(A, ctx);
74 TEMPLATE(T, mat_clear)(B, ctx);
75 TEMPLATE(T, mat_clear)(X, ctx);
76 TEMPLATE(T, mat_clear)(AX, ctx);
77
78 TEMPLATE(T, ctx_clear) (ctx);
79 }
80
81 for (i = 0; i < 1000 * flint_test_multiplier(); i++)
82 {
83 TEMPLATE(T, ctx_randtest) (ctx, state);
84
85 m = 1 + n_randint(state, 20);
86 n = 1 + n_randint(state, 20);
87 r = n_randint(state, m);
88
89 TEMPLATE(T, mat_init)(A, m, m, ctx);
90 TEMPLATE(T, mat_init)(B, m, n, ctx);
91 TEMPLATE(T, mat_init)(X, m, n, ctx);
92 TEMPLATE(T, mat_init)(AX, m, n, ctx);
93
94 TEMPLATE(T, mat_randrank)(A, state, r, ctx);
95 TEMPLATE(T, mat_randtest)(B, state, ctx);
96
97 /* Dense */
98 if (n_randint(state, 2))
99 TEMPLATE(T, mat_randops)(A, 1+n_randint(state, 1+m*m), state, ctx);
100
101 solved = TEMPLATE(T, mat_solve)(X, A, B, ctx);
102
103 if (solved)
104 {
105 flint_printf("FAIL:\n");
106 flint_printf("singular system was 'solved'\n");
107 TEMPLATE(T, mat_print_pretty)(A, ctx);
108 TEMPLATE(T, mat_print_pretty)(X, ctx);
109 TEMPLATE(T, mat_print_pretty)(B, ctx);
110 abort();
111 }
112
113 TEMPLATE(T, mat_clear)(A, ctx);
114 TEMPLATE(T, mat_clear)(B, ctx);
115 TEMPLATE(T, mat_clear)(X, ctx);
116 TEMPLATE(T, mat_clear)(AX, ctx);
117
118 TEMPLATE(T, ctx_clear) (ctx);
119 }
120
121 FLINT_TEST_CLEANUP(state);
122 printf("PASS\n");
123 return 0;
124 }
125
126
127 #endif
128