-
Notifications
You must be signed in to change notification settings - Fork 36
/
RandMat.cpp
61 lines (53 loc) · 1006 Bytes
/
RandMat.cpp
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
#include "RandMat.h"
RandMat::RandMat() {}
void RandMat::init(int dim, int is_mb)
{
mat_GF2 mat;
int hw;
mat.SetDims(dim, dim);
this->dim = dim;
do {
for (int i = 0; i < dim; i++)
{
do
{
hw = 0;
for (int j = 0; j < dim; j++)
{
mat[i][j] = random_GF2();
if (mat[i][j] == 1)
hw += 1;
}
} while (hw == 1);
}
this->mat = mat;
if (is_mb == 0) {
return;
}
} while (determinant(mat) == 0);
this->invMat = inv(mat);
}
ostream& operator<<(ostream& stream, const RandMat& rMat)
{
cout << "Dim=" << rMat.dim << endl;
for (int i = 0; i < rMat.dim; i++)
{
for (int j = 0; j < rMat.dim; j++)
{
cout << rMat.mat[i][j] << " ";
}
cout << endl;
}
cout << endl;
if (determinant(rMat.mat) == 0)
return stream;
for (int i = 0; i < rMat.dim; i++)
{
for (int j = 0; j < rMat.dim; j++)
{
cout << rMat.invMat[i][j] << " ";
}
cout << endl;
}
return stream;
}