Skip to content

Instantly share code, notes, and snippets.

@liaocs2008
Created August 11, 2020 19:29
Show Gist options
  • Save liaocs2008/eb16a9c1ba7e8c2ec4d8c5000b8f7522 to your computer and use it in GitHub Desktop.
Save liaocs2008/eb16a9c1ba7e8c2ec4d8c5000b8f7522 to your computer and use it in GitHub Desktop.
Generate np array from alist format
## note, run with py27
import itertools
import numpy as np
from lpdec.codes import BinaryLinearBlockCode
from lpdec.codes.ldpc import ArrayLDPCCode
from lpdec.channels import *
from lpdec.decoders.iterative import IterativeDecoder
for fname in ['BCH_63_36_5_strip.alist', 'BCH_63_45_3_strip.alist', 'BCH_63_51_2_strip.alist', 'BCH_31_16_3_strip.alist']:
code = BinaryLinearBlockCode(parityCheckMatrix=fname)
base = fname.split('.')[0]
np.save(base + '_G.npy', code.generatorMatrix)
np.save(base + '_H.npy', code.parityCheckMatrix)
for fname in ['ArrayCode_N49_K24_r0.49.alist', 'ArrayCode_N121_K60_r0.50.alist', 'ArrayCode_N121_K70_r0.58.alist', 'ArrayCode_N121_K80_r0.66.alist']:
code2 = BinaryLinearBlockCode(parityCheckMatrix=fname)
p = 11
r = None
if 'K24' in fname:
r = 4
p = 7
elif 'K60' in fname:
r = 6
elif 'K70' in fname:
r = 5
elif 'K80' in fname:
r = 4
code = ArrayLDPCCode(p, r)
assert np.all(code.parityCheckMatrix == code2.parityCheckMatrix)
assert np.all(code.generatorMatrix == code2.generatorMatrix)
print(fname, "code=code2")
base = fname.split('.')[0]
np.save(base + '_G.npy', code.generatorMatrix)
np.save(base + '_H.npy', code.parityCheckMatrix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment