-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.cpp
More file actions
96 lines (83 loc) · 2.22 KB
/
Test.cpp
File metadata and controls
96 lines (83 loc) · 2.22 KB
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
/*
* MyTest.cpp
*
* Created on: Feb 15, 2016
* Author: wing
*/
#include<iostream>
#include "MyLdpc.h"
using namespace std;
void test2() {
const int z = 24;
const int ldpcN = z * 24;
const int ldpcK = ldpcN / 6 * 5;
const int ldpcM = ldpcN - ldpcK;
const enum rate_type rate = rate_5_6;
Coder coder(ldpcK, ldpcN, rate);
const int srcLength = 10;
char * srcCode = (char*) malloc(srcLength);
char * priorCode = (char*) malloc(coder.getPriorCodeLength(srcLength));
int * priorCodeInt = (int*) malloc(
sizeof(int) * 8 * coder.getPriorCodeLength(srcLength));
float * postCode = (float*) malloc(coder.getPostCodeLength(srcLength));
char * newSrcCode = (char*) malloc(srcLength);
for (int i = 0; i < srcLength; i++) {
srcCode[i] = 'a' + i % 26;
}
coder.forEncoder();
coder.forDecoder(1);
coder.encode(srcCode, priorCode, srcLength);
using namespace Eigen;
typedef Triplet<DataType> T;
std::vector<T> tripletList;
SparseMatrix<int> smN(ldpcN,1);
cout << "Right code = " << endl;
for (int i = 0; i < coder.getPriorCodeLength(srcLength); ++i) {
char tmp = priorCode[i];
for (int j = 0; j < 8; ++j) {
if (tmp & (1 << (7-j))) {
priorCodeInt[i * 8 + j] = 1;
tripletList.push_back(T(i * 8 + j, 0, 1));
cout << "1 ";
} else {
priorCodeInt[i * 8 + j] = 0;
cout << "0 ";
}
}
}
cout << endl;
//cout<<coder.checkMatrix<<endl;
smN.setFromTriplets(tripletList.begin(),tripletList.end());
LOGA(coder.checkMatrix.cols());
LOGA(smN.rows());
coder.test(priorCode, postCode, coder.getPostCodeLength(srcLength), 0.1);
coder.decode(postCode, newSrcCode, srcLength);
cout<<"srcCode=";
for (int i = 0; i < srcLength; i++) {
cout << srcCode[i];
}
cout << endl;
cout<<"newSrcCode=";
for (int i = 0; i < srcLength; i++) {
cout << newSrcCode[i];
}
cout << endl;
}
void test3() {
using namespace Eigen;
SparseMatrix<int> a(2, 2);
a.insert(0, 0) = 1;
a.insert(0, 1) = 1;
a.insert(1, 1) = 0;
a.insert(1, 0) = 0;
a.makeCompressed();
cout << a.nonZeros() << endl;
for (int k = 0; k < a.outerSize(); ++k)
for (SparseMatrix<int>::InnerIterator it(a, k); it; ++it) {
cout << "k=" << k << endl;
cout << it.value() << " " << it.row() << " " << it.col() << endl;
}
}
int main() {
test2();
}