-
Notifications
You must be signed in to change notification settings - Fork 7
/
main_mmrg.cc
208 lines (168 loc) · 5.45 KB
/
main_mmrg.cc
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//
// main_for_mmrg.cc
// LatMRG
//
// Main program to test the new MMRG class
//
// select pre compiling options
//----------------------------------------------------------------------------------------
#define PRINT_CONSOLE
//----------------------------------------------------------------------------------------
#include <iostream>
#include <map>
#include <fstream>
#include <iterator>
#include <string>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <num.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/progress.hpp>
#include <NTL/tools.h>
#include <NTL/ctools.h>
#include <NTL/ZZ.h>
#include <NTL/ZZ_p.h>
#include "NTL/vec_ZZ.h"
#include "NTL/vec_ZZ_p.h"
#include <NTL/vec_vec_ZZ.h>
#include <NTL/vec_vec_ZZ_p.h>
#include <NTL/mat_ZZ.h>
#include <NTL/matrix.h>
#include <NTL/LLL.h>
#include "latticetester/Types.h"
#include "latticetester/Util.h"
#include "latmrg/IntLattice.h"
#include "latmrg/LatTestAll.h"
#include "latmrg/MRGLattice.h"
#include "latmrg/MMRGLattice.h"
//#include "SimpleMRG.h"
using namespace std;
using namespace NTL;
using namespace LatticeTester;
using namespace LatMRG;
void SavvidyMatrix(mat_ZZ& A, int N, int s, int m, int b)
{
A.kill();
A.SetDims(N,N);
for (int j = 1; j < N; j ++) {
for (int i = j+1; i < N; i++)
A[i][j] = (i-j+2) * m + b;
}
for (int i = 0; i < N; i ++)
A[i][0] = 1;
for (int i = 1; i < N; i++)
A[i][i] = 2;
for (int i = 0; i < N; i ++) {
for (int j = i+1; j < N; j ++)
A[i][j] = 1;
}
A[2][1] += s;
}
void LacunaryMatrix (mat_ZZ& B, mat_ZZ& A, vec_ZZ& lacunaryIndices)
{
int L = (int) lacunaryIndices.length();
int N = (int) A.NumCols();
B.SetDims(L, N);
for (int k = 0; k < L; k++)
B[k][conv<int>(lacunaryIndices[k])-1] = 1;
}
void printMatrixForInputFile (mat_ZZ A)
{
for (int i = 0; i < A.NumRows(); i++) {
for (int j = 0; j < A.NumCols(); j++) {
cout << A[i][j] << " ";
}
cout << endl;
}
}
//*=======================================================================================
#if 0
int main ()
{
// modulus
//ZZ m = power_ZZ(2,3)-1;
ZZ m = power_ZZ(2,7)-1; //=127
// dimension of projection
int dimension = 7;
// generator matrix
int r = 5;
MMat A;
SavvidyMatrix(A, r, -1, 1, 0);
// MMRG
MMRGLattice myMMRG (m, A, dimension, r, L2NORM, FULL);
cout << "A = \n" << myMMRG.toStringGeneratorMatrix() << endl;
// MMRG lacunary
vec_ZZ lacunaryIndices;
lacunaryIndices.SetLength(3);
lacunaryIndices[0] = 1;
lacunaryIndices[1] = 3;
lacunaryIndices[2] = 5;
//lacunaryIndices[3] = 4;
//lacunaryIndices[4] = 5;
MMat B;
LacunaryMatrix(B, A, lacunaryIndices);
cout << "lac B = \n" << B << endl;
MMRGLattice myLacMMRG (m, A, dimension, r, L2NORM, FULL);
cout << "lac A = \n" << myLacMMRG.toStringGeneratorMatrix() << endl;
cout << "\n----- Build basis non lac -----" << endl;
myMMRG.buildNonLacunaryBasis(dimension);
cout << "Primal basis = \n";
printMatrixForInputFile(myMMRG.getBasis());
cout << "Dual basis = \n";
printMatrixForInputFile(myMMRG.getDualBasis());
cout << "m_dualVecNorm = " << myMMRG.getDualVecNorm() << endl;
//cout << "V*transpose(W) = \n" << myMMRG.getBasis() * transpose(myMMRG.getDualBasis()) << endl;
cout << "\n----- Build basis lac -----" << endl;
myLacMMRG.buildLacunaryBasis(dimension, B);
cout << "Primal basis = \n";
printMatrixForInputFile(myLacMMRG.getBasis());
cout << "Dual basis = \n";
printMatrixForInputFile(myLacMMRG.getDualBasis());
cout << "m_dualVecNorm = " << myLacMMRG.getDualVecNorm() << endl;
//cout << "V*transpose(W) = \n" << myLacMMRG.getBasis() * transpose(myLacMMRG.getDualBasis()) << endl;
cout << "\n----- Increment dim non lac -----" << endl;
for (int j = 0; j < 10; j++)
myMMRG.incrementDimBasis();
cout << "Primal basis = \n";
printMatrixForInputFile(myMMRG.getBasis());
//cout << "Dual basis = \n" << myMMRG.getDualBasis() << endl;
//cout << "V*transpose(W) = \n" << myMMRG.getBasis() * transpose(myMMRG.getDualBasis()) << endl;
cout << "\n--- Increment dim lac ---" << endl;
for (int j = 0; j < 10; j++)
myLacMMRG.incrementDimLacunaryBasis(B);
cout << "Primal basis = \n";
printMatrixForInputFile(myLacMMRG.getBasis());
//cout << "Dual basis = \n" << myLacMMRG.getDualBasis() << endl;
//cout << "V*transpose(W) = \n" << myLacMMRG.getBasis() * transpose(myLacMMRG.getDualBasis()) << endl;
return 0;
}
#endif
//*=======================================================================================
#if 0
int main (int argc, char *argv[])
{
// Erwan
//string testLocation = "/Users/Erwan1/projects/github/LatMRG";
//string testLocation = "/Users/Erwan1/projects/github/LatMRG/latZZDD_test1";
// Paul
//string testLocation = "/Users/paulwambergue/UdeM/latmrg/inputTestFiles";
string testLocation = "/Users/paulwambergue/UdeM/latmrg/inputTestFiles/latZZDD_test1";
struct stat buf; //properties of a file or directory
LatMRG::LatTestAll testall;
int status = 0;
stat(testLocation.c_str(), &buf);
if (0 != S_ISDIR(buf.st_mode)) //directory
status |= testall.doTestDir (testLocation.c_str());
else { //file
string dataname(testLocation.c_str());
dataname.append(".dat");
stat(dataname.c_str(), &buf);
status |= testall.doTest (testLocation.c_str());
}
return 0;
}
#endif