summaryrefslogtreecommitdiff
path: root/controller/fw/ldpc_decoder_test.py
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2020-02-28 18:29:41 +0100
committerjaseg <git-bigdata-wsl-arch@jaseg.de>2020-02-28 18:29:41 +0100
commit89b32316aa46f22a4f967ca7953089a3df0c16e7 (patch)
treefddb3fd4538d3a52ab7a23a9275497f824d482bc /controller/fw/ldpc_decoder_test.py
parent9cf1fee2e9f625ca6787e3b14c759be43ea663e6 (diff)
downloadmaster-thesis-89b32316aa46f22a4f967ca7953089a3df0c16e7.tar.gz
master-thesis-89b32316aa46f22a4f967ca7953089a3df0c16e7.tar.bz2
master-thesis-89b32316aa46f22a4f967ca7953089a3df0c16e7.zip
embedded ldpc decoder 50% working
Diffstat (limited to 'controller/fw/ldpc_decoder_test.py')
-rw-r--r--controller/fw/ldpc_decoder_test.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/controller/fw/ldpc_decoder_test.py b/controller/fw/ldpc_decoder_test.py
new file mode 100644
index 0000000..d5cbb24
--- /dev/null
+++ b/controller/fw/ldpc_decoder_test.py
@@ -0,0 +1,53 @@
+
+import pyldpc
+import scipy.sparse
+import numpy as np
+import test_decoder
+import os, sys
+import ctypes as C
+import argparse
+
+if __name__ != '__main__':
+ raise RuntimeError("Please don't import this module, this is a command-line program.")
+
+parser = argparse.ArgumentParser()
+parser.add_argument('-r', '--reference', action='store_true', default=False, help='Run reference decoder instead of C implemention')
+args = parser.parse_args()
+
+lib = C.CDLL('./ldpc_decoder_test.so')
+
+n = 384
+nodes, bits = 6, 8
+H, G = pyldpc.make_ldpc(n, nodes, bits, systematic=False, seed=0)
+_1, bits_pos, _2 = scipy.sparse.find(H)
+_, k = G.shape
+
+st = np.random.RandomState(seed=0)
+test_data = st.randint(0, 2, k)
+d = np.dot(G, test_data) % 2
+x = (-1) ** d
+
+bits_pos = bits_pos.astype(np.uint32)
+x = x.astype(np.int8)
+
+lib.decode.argtypes = [C.c_size_t, C.c_size_t, C.c_size_t, C.POINTER(C.c_size_t), C.POINTER(C.c_int8), C.POINTER(C.c_int8), C.c_uint]
+
+if args.reference:
+ ref_out = test_decoder.decode(H, x, 3)
+ print('decoder output:', ref_out, flush=True)
+ print('msg reconstruction:', pyldpc.get_message(G, ref_out))
+ print('reference decoder: ', np.all(np.equal(pyldpc.get_message(G, ref_out), test_data)), flush=True)
+ print(ref_out.dtype)
+
+else:
+ out = np.zeros(n, dtype=np.uint8)
+ # print('python data:', x, flush=True)
+ print('decoder iterations:', lib.decode(n, nodes, bits,
+ bits_pos.ctypes.data_as(C.POINTER(C.c_ulong)),
+ x.ctypes.data_as(C.POINTER(C.c_int8)),
+ out.ctypes.data_as(C.POINTER(C.c_int8)),
+ 25), flush=True)
+ print('decoder output:', out)
+ print('msg reconstruction:', pyldpc.get_message(G, out))
+ print('decoder under test:', np.all(np.equal(pyldpc.get_message(G, out.astype(np.int64)), test_data)))
+ print(out.dtype)