-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix nrPolarDecode() and add more tests (#71)
* fix minsum function in nrPolarDecode() * fix wrong bpsk mod * add test_nrPolarDecode.py and test_nrPolarEncode_nrPolarDecode.py * bump version to 0.3.6
- Loading branch information
Showing
5 changed files
with
157 additions
and
11 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
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,31 @@ | ||
import numpy as np | ||
import pytest | ||
from py3gpp.nrPolarDecode import nrPolarDecode | ||
|
||
def test_nrPolarDecode(): | ||
nmax = 9 | ||
K = 100 | ||
|
||
# --- TESTCASE1 --- | ||
payload = np.ones(K).astype(int) | ||
cw = np.array([0,1,0,0,0,1,1,0,1,1,0,1,0,0,1,0,0,0,1,0,1,0,0,0,0,0,1,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,1,1,0,0,0,1,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,0,0,1,0,1,1,1,0,0,0,1,0,1,1,0,0,1,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,0,1,1,0,1,0,0,1,1,0,0,1,1,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,0,1,0,1,1,0,0,0,0,0,0,1,1,0,1,0,1,0,0,0,0,1,0,1,1,0,0,1,0,1,0,1,0,1,0,0,0,1,0,1,1,0,1,0,1,1,1,1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,1,0,0,1,1,0,0,0,0,1,0,1,1,0,1,0,1,1,0,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,0,1,1,1,1,1,1,0,1,1,0,1,0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,1,0,0,0,0,0,0,1,1,0,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,0,0,0,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,0,1,0,1,1,0,1,1,1,1,1,1,1,0,1,1,1,0,1,0,1,0,0,1,1,1,1,0,0,0,1,0,0,0,1,1,0,0,0,1,1,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,1,1,1,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,1,1,1,1,1,1,0,0,1,1,0,1,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,1,0,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]) | ||
cw_llr = -2*cw.astype(np.float64) + 1 | ||
cw_llr[100:300] = 0 # introduce some errors | ||
|
||
payload_decoded = nrPolarDecode(cw_llr, K, 512, 10, nmax = nmax, iil = False) | ||
assert payload_decoded.shape[0] == K | ||
assert np.array_equal(payload, payload_decoded) | ||
|
||
# --- TESTCASE2 --- | ||
payload = np.array([1,0,1,1,0,0,1,0,1,1,0,0,1,1,1,1,1,0,1,0,1,1,0,1,0,1,1,1,1,1,0,0,0,1,1,1,1,0,0,1,1,0,0,1,1,1,0,0,0,0,1,1,0,1,0,1,0,0,0,1,1,1,0,0,1,1,0,0,0,1,0,0,1,0,1,1,0,1,0,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1,1,1,0,0,0,0,1,1,1,1,0,1,0,1,0,0,0,0,0,0,0,1,1,1,0,1]) | ||
cw_llr = -2*cw.astype(np.float64) + 1 | ||
cw_llr[100:300] = 0 # introduce some errors | ||
|
||
payload_decoded = nrPolarDecode(cw_llr, K, 512, 10, nmax = nmax, iil = False) | ||
assert payload_decoded.shape[0] == K | ||
assert np.array_equal(payload_decoded, payload) | ||
|
||
|
||
if __name__ == '__main__': | ||
test_nrPolarDecode() |
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,69 @@ | ||
import numpy as np | ||
import pytest | ||
from py3gpp.nrPolarEncode import nrPolarEncode | ||
from py3gpp.nrPolarDecode import nrPolarDecode | ||
|
||
@pytest.mark.parametrize('K', [100, 151, 200]) | ||
@pytest.mark.parametrize('nmax', [9, 10]) | ||
@pytest.mark.parametrize('iil', [True, False]) | ||
def test_nrPolarEncode_nrPolarDecode_generic(K, nmax, iil, repetitions = 100): | ||
for _ in np.arange(repetitions): | ||
if iil and K > 164: | ||
# print("skipping test, because iil is not supported for K > 164") | ||
continue | ||
payload = np.random.randint(2, size=K) | ||
cw = nrPolarEncode(payload, 2**nmax, nmax=nmax, iil=iil) | ||
|
||
cw_llr = -2*cw.astype(np.float64) + 1 | ||
if K < 150: | ||
cw_llr[100:300] = 0 # introduce some errors | ||
else: | ||
cw_llr[100:200] = 0 # introduce some errors | ||
|
||
payload_decoded = nrPolarDecode(cw_llr, K, 2**nmax, 10, nmax = nmax, iil = iil) | ||
assert payload_decoded.shape[0] == K | ||
assert np.array_equal(payload, payload_decoded) | ||
|
||
def test_nrPolarEncode_nrPolarDecode_fixed(): | ||
nmax = 9 | ||
K = 100 | ||
payload = np.ones(K).astype(int) | ||
|
||
# --- TESTCASE 1 --- | ||
for iil in [True, False]: | ||
cw = nrPolarEncode(payload, 512, nmax=nmax, i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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]) | ||
assert np.array_equal(cw, cw_desired) | ||
|
||
cw_llr = -2*cw.astype(np.float64) + 1 | ||
cw_llr[100:300] = 0 # introduce some errors | ||
|
||
payload_decoded = nrPolarDecode(cw_llr, K, 512, 10, nmax = nmax, iil = iil) | ||
assert payload_decoded.shape[0] == K | ||
assert np.array_equal(payload, payload_decoded) | ||
|
||
payload = np.ones(100).astype(int) | ||
payload[:10] = 0 | ||
|
||
# --- TESTCASE 2 --- | ||
for iil in [True, False]: | ||
cw = nrPolarEncode(payload, 512, nmax=nmax, iil=iil) | ||
if iil: | ||
cw_desired = np.array([0,1,0,1,1,1,0,0,0,1,1,0,0,0,1,0,1,1,0,0,1,1,0,1,0,1,1,1,0,0,1,0,1,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,0,0,0,1,1,1,1,0,1,1,1,1,0,1,0,0,1,0,1,1,0,0,0,1,1,1,0,0,0,1,0,0,1,1,0,0,0,1,1,0,0,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,1,1,0,0,1,1,0,0,1,0,0,0,1,1,0,0,0,0,1,1,1,1,1,0,1,0,0,0,0,1,0,0,0,1,1,1,1,0,1,0,1,1,0,0,1,0,0,0,1,0,0,0,0,1,1,1,1,1,0,0,1,0,0,0,0,0,1,1,0,1,0,0,1,0,0,0,1,0,1,1,0,1,1,1,1,0,1,0,1,0,0,0,1,1,1,1,1,0,0,0,1,1,0,1,1,0,0,0,1,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,1,1,0,1,0,1,1,1,0,0,1,1,1,1,0,1,1,1,0,0,0,1,1,0,0,0,1,1,1,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,1,0,1,1,0,1,0,0,0,0,0,1,1,0,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,0,1,0,1,0,1,0,1,1,0,1,1,1,1,1,1,1,0,1,1,1,0,1,0,1,0,0,1,1,1,1,0,0,0,1,0,0,0,1,1,0,0,0,1,1,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,1,1,1,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,1,1,1,1,1,1,0,0,1,1,0,1,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,1,0,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]) | ||
assert np.array_equal(cw, cw_desired) | ||
|
||
cw_llr = -2*cw.astype(np.float64) + 1 | ||
cw_llr[100:300] = 0 # introduce some errors | ||
|
||
payload_decoded = nrPolarDecode(cw_llr, K, 512, 10, nmax = nmax, iil = iil) | ||
assert payload_decoded.shape[0] == K | ||
assert np.array_equal(payload, payload_decoded) | ||
|
||
if __name__ == '__main__': | ||
# test_nrPolarEncode_nrPolarDecode_fixed() | ||
test_nrPolarEncode_nrPolarDecode_generic(K = 200, nmax = 9, iil = False, repetitions = 100) |