-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgf2e_mat_solve.cpp
63 lines (49 loc) · 1.24 KB
/
gf2e_mat_solve.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
62
#include <linbox/linbox-config.h>
#include <iostream>
#include <linbox/ring/modular.h>
#include <linbox/matrix/sparse-matrix.h>
#include <linbox/solutions/solve.h>
#include <linbox/solutions/methods.h>
using namespace LinBox;
using namespace std;
#include "gf2e_mat_solve.h"
void initField(int fieldSize){
typedef LinBox::NTL_GF2E Field;
Field F(2, fieldSize);
}
int solve_api(const GF2EMatrix & A, const GF2EVector & B, GF2EVector & X, int fieldSize) {
typedef LinBox::NTL_GF2E Field;
Field F(2, fieldSize);
size_t rows = A.size();
if(0 == rows) {
return -__LINE__;
}
if(B.size() != rows) {
return -__LINE__;
}
size_t cols = A[0].size();
if(0 == cols) {
return -__LINE__;
}
SparseMatrix<Field> mA(F, rows, cols);
for(size_t i = 0; i < rows; ++i) {
for(size_t j = 0; j < cols; ++j) {
mA.setEntry(i, j, A[i][j]);
}
}
DenseVector<Field> vB(F, rows);
DenseVector<Field>::iterator i = vB.begin();
GF2EVector::const_iterator j = B.begin();
while(i != vB.end() && j != B.end()) {
*i++ = *j++;
}
DenseVector<Field> vX(F, cols);
solve(vX, mA, vB, Method::SparseElimination());
X.resize(cols);
i = vX.begin();
GF2EVector::iterator k = X.begin();
while(i != vX.end() && k != X.end()) {
*k++ = *i++;
}
return 0;
}