1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
Copyright (C) 2010, 2011, 2024 Fredrik Johansson
This file is part of FLINT.
FLINT is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include "fmpz.h"
#include "fmpz_vec.h"
#include "fmpz_mat.h"
void
fmpz_mat_mul_classical(fmpz_mat_t C, const fmpz_mat_t A, const fmpz_mat_t B)
{
slong ar, br, bc, i, j;
ar = fmpz_mat_nrows(A);
br = fmpz_mat_nrows(B);
bc = fmpz_mat_ncols(B);
if (ar == 0 || br == 0 || bc == 0)
{
fmpz_mat_zero(C);
return;
}
if (br == 1)
{
for (i = 0; i < ar; i++)
{
for (j = 0; j < bc; j++)
{
fmpz_mul(fmpz_mat_entry(C, i, j),
fmpz_mat_entry(A, i, 0),
fmpz_mat_entry(B, 0, j));
}
}
}
else if (br == 2)
{
for (i = 0; i < ar; i++)
{
for (j = 0; j < bc; j++)
{
fmpz_fmma(fmpz_mat_entry(C, i, j),
fmpz_mat_entry(A, i, 0),
fmpz_mat_entry(B, 0, j),
fmpz_mat_entry(A, i, 1),
fmpz_mat_entry(B, 1, j));
}
}
}
else
{
fmpz * tmp;
TMP_INIT;
TMP_START;
tmp = TMP_ALLOC(sizeof(fmpz) * br * bc);
for (i = 0; i < br; i++)
for (j = 0; j < bc; j++)
tmp[j * br + i] = *fmpz_mat_entry(B, i, j);
for (i = 0; i < ar; i++)
{
for (j = 0; j < bc; j++)
{
_fmpz_vec_dot_general(fmpz_mat_entry(C, i, j),
NULL, 0, fmpz_mat_entry(A, i, 0), tmp + j * br, 0, br);
}
}
TMP_END;
}
}