1 /*
2 Copyright (C) 2011 Fredrik Johansson
3 Copyright (C) 2014 Abhinav Baid
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 <https://www.gnu.org/licenses/>.
11 */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <gmp.h>
16 #include "flint.h"
17 #include "fmpz.h"
18 #include "fmpz_mat.h"
19 #include "nmod_mat.h"
20 #include "ulong_extras.h"
21 #include "long_extras.h"
22
23 int
main(void)24 main(void)
25 {
26 int i;
27 FLINT_TEST_INIT(state);
28
29
30 flint_printf("scalar_mul/tdiv_q_2exp....");
31 fflush(stdout);
32
33 for (i = 0; i < 100 * flint_test_multiplier(); i++)
34 {
35 fmpz_mat_t C, B, A;
36 slong rows, cols;
37 ulong exp;
38
39 rows = n_randint(state, 10);
40 cols = n_randint(state, 10);
41
42 fmpz_mat_init(A, rows, cols);
43 fmpz_mat_init(B, rows, cols);
44 fmpz_mat_init(C, rows, cols);
45
46 exp = n_randint(state, 200);
47 fmpz_mat_randtest(A, state, 100);
48
49 fmpz_mat_scalar_mul_2exp(B, A, exp);
50 fmpz_mat_scalar_tdiv_q_2exp(C, B, exp);
51
52 if (!fmpz_mat_equal(C, A))
53 {
54 flint_printf("FAIL!\n");
55 abort();
56 }
57
58 fmpz_mat_clear(A);
59 fmpz_mat_clear(B);
60 fmpz_mat_clear(C);
61 }
62
63 /* test aliasing */
64 for (i = 0; i < 100 * flint_test_multiplier(); i++)
65 {
66 fmpz_mat_t C, B, A;
67 slong rows, cols;
68 ulong exp;
69
70 rows = n_randint(state, 10);
71 cols = n_randint(state, 10);
72
73 fmpz_mat_init(A, rows, cols);
74 fmpz_mat_init(B, rows, cols);
75 fmpz_mat_init(C, rows, cols);
76
77 exp = n_randint(state, 200);
78 fmpz_mat_randtest(A, state, 100);
79
80 fmpz_mat_scalar_mul_2exp(B, A, exp);
81 fmpz_mat_scalar_tdiv_q_2exp(C, B, exp);
82 fmpz_mat_scalar_mul_2exp(A, A, exp);
83 fmpz_mat_scalar_tdiv_q_2exp(A, A, exp);
84
85 if (!fmpz_mat_equal(C, A))
86 {
87 flint_printf("FAIL!\n");
88 abort();
89 }
90
91 fmpz_mat_clear(A);
92 fmpz_mat_clear(B);
93 fmpz_mat_clear(C);
94 }
95
96 FLINT_TEST_CLEANUP(state);
97 flint_printf("PASS\n");
98 return 0;
99 }
100