-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- includes testing operations on G and H
- Loading branch information
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "../src/core/ldpc.h" | ||
#include "../include/argparse/argparse.hpp" | ||
|
||
#include "ldpctest.cpp" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
argparse::ArgumentParser parser("ldpc_tests"); | ||
parser.add_argument("codefile").help("LDPC codefile containing all non-zero entries, compressed sparse row (CSR) format."); | ||
parser.add_argument("-G").help("Generator matrix, compressed sparse row (CSR) format.").default_value(std::string("")); | ||
|
||
std::string pcFile, genFile; | ||
try | ||
{ | ||
parser.parse_args(argc, argv); | ||
pcFile = parser.get<std::string>("codefile"); | ||
genFile = parser.get<std::string>("-G"); | ||
} | ||
catch (const std::runtime_error &e) | ||
{ | ||
std::cout << e.what() << std::endl; | ||
std::cout << parser; | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
try | ||
{ | ||
ldpc::ldpc_code code(pcFile, genFile); | ||
ldpc_tests::gf2(); | ||
ldpc_tests::is_generator_matrix(code); | ||
ldpc_tests::codeword(code); | ||
|
||
std::cout << "All tests passed." << std::endl; | ||
} | ||
catch (const std::exception &e) | ||
{ | ||
std::cout << "Assessment failed: " << e.what() << std::endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "../src/core/ldpc.h" | ||
|
||
namespace ldpc_tests | ||
{ | ||
void gf2() | ||
{ | ||
try | ||
{ | ||
auto check = ldpc::bits_t(0); | ||
if ((check * 1) != 0) throw 0; | ||
if ((check + 1) == 0) throw 0; | ||
if ((check + 1 + 1) != 0) throw 0; | ||
if ((-check) == 0) throw 0; | ||
} | ||
catch (...) | ||
{ | ||
throw std::runtime_error("failed: gf2 arithmetics"); | ||
} | ||
std::cout << "passed: gf2 arithmetics" << std::endl; | ||
} | ||
|
||
void is_generator_matrix(const ldpc::ldpc_code &code) | ||
{ | ||
for (ldpc::u64 i = 0; i < code.mc(); i++) // rows of H | ||
{ | ||
for (ldpc::u64 j = 0; j < code.kc(); j++) // cols of G transpose = rows of G | ||
{ | ||
auto &h = code.H().row_neighbor()[i]; | ||
auto &g = code.G().row_neighbor()[j]; | ||
|
||
auto sum = ldpc::bits_t(0); | ||
for (auto hi : h) | ||
{ | ||
for (auto gj : g) | ||
{ | ||
sum += (hi.nodeIndex == gj.nodeIndex) * | ||
code.G().nz_entry()[gj.edgeIndex].value * | ||
code.H().nz_entry()[hi.edgeIndex].value; | ||
} | ||
} | ||
|
||
if (sum != 0) | ||
{ | ||
throw std::runtime_error("failed: is_generator_matrix"); | ||
} | ||
} | ||
} | ||
|
||
std::cout << "passed: is_generator_matrix" << std::endl; | ||
} | ||
|
||
void codeword(const ldpc::ldpc_code &code) | ||
{ | ||
ldpc::vec_bits_t u(code.kc(), 1); | ||
for (auto &x : u) | ||
{ | ||
x = rand() % 2; | ||
} | ||
auto cw = code.G().multiply_left(u); | ||
auto synd = code.H().multiply_right(cw); | ||
|
||
for (auto s : synd) | ||
{ | ||
if (s != 0) | ||
{ | ||
throw std::runtime_error("failed: encoding random information word"); | ||
} | ||
} | ||
|
||
std::cout << "passed: encoding random information word" << std::endl; | ||
} | ||
} // namespace ldpc_tests |