Skip to content

Commit a7f74db

Browse files
author
grigory
committed
Reorganize code of SC Polar codec
1 parent cc070ac commit a7f74db

File tree

12 files changed

+33
-179
lines changed

12 files changed

+33
-179
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .codec import BasePolarCodec, BasePolarCodeWithCRC
1+
from .codec import BaseCRCPolarCodec, BasePolarCodec
22
from .decoder import BaseDecoder
3-
from .functions import *
43
from .decoding_path import DecodingPathMixin
4+
from .functions import *

python_polar_coding/polar_codes/base/codec.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import abc
2-
from operator import itemgetter
32
from typing import Union
3+
from operator import itemgetter
44

55
import numpy as np
66

7+
from python_polar_coding.polar_codes import crc, pcc, utils
8+
79
from . import encoder
8-
from python_polar_coding.polar_codes import utils, crc, pcc
910

1011

1112
class BasePolarCodec(metaclass=abc.ABCMeta):
@@ -133,7 +134,7 @@ def _construct_polar_mask(self, K):
133134
return np.array([m[2] for m in mask])
134135

135136

136-
class BasePolarCodeWithCRC(BasePolarCodec):
137+
class BaseCRCPolarCodec(BasePolarCodec):
137138
"""Basic Polar code class with CRC support.
138139
139140
Provides the support of CRC 16 and CRC 32.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .codec import SCPolarCodec
2+
from .decoder import SCDecoder
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from .base.polar_code import BasicPolarCode
2-
from .decoders import SCDecoder
1+
from ..base import BasePolarCodec
2+
from .decoder import SCDecoder
33

44

5-
class SCPolarCode(BasicPolarCode):
5+
class SCPolarCodec(BasePolarCodec):
66
"""Polar code with SC decoding algorithm."""
77
decoder_class = SCDecoder
88

9-
def get_decoder(self):
9+
def init_decoder(self):
1010
return self.decoder_class(
1111
n=self.n, mask=self.mask, is_systematic=self.is_systematic
1212
)

python_polar_coding/polar_codes/decoders/sc_decoder.py renamed to python_polar_coding/polar_codes/sc/decoder.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import numba
22
import numpy as np
33

4-
from ..base.decoder import BaseDecoder
5-
from ..base.functions import compute_encoding_step
4+
from ..base import decoder, functions
65

76

8-
class SCDecoder(BaseDecoder):
7+
class SCDecoder(decoder.BaseDecoder):
98
"""Implements SC decoding algorithm.
109
1110
Stores initial and intermediate LLR values, intermediate bit values and
@@ -134,7 +133,7 @@ def _compute_intermediate_beta(self, position):
134133
source = self.intermediate_bits[i + 1]
135134
result = self.intermediate_bits[i]
136135

137-
self.intermediate_bits[i] = compute_encoding_step(
136+
self.intermediate_bits[i] = functions.compute_encoding_step(
138137
i, self.n, source, result
139138
)
140139

File renamed without changes.

python_polar_coding/tests/test_base/test_basic_polar_code.py renamed to python_polar_coding/tests/test_base/test_codec.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import numpy as np
44

5-
from python_polar_coding.polar_codes.base.decoder import BaseDecoder
6-
from python_polar_coding.polar_codes.base.functions import make_hard_decision
7-
from python_polar_coding.polar_codes.base.polar_code import (
8-
BasicPolarCode,
9-
BasicPolarCodeWithCRC,
5+
from python_polar_coding.polar_codes.base import (
6+
BaseCRCPolarCodec,
7+
BaseDecoder,
8+
BasePolarCodec,
9+
make_hard_decision,
1010
)
1111

1212

@@ -16,21 +16,21 @@ def decode_internal(self, received_llr: np.array):
1616
return make_hard_decision(received_llr)
1717

1818

19-
class SimplePC(BasicPolarCode):
19+
class SimplePC(BasePolarCodec):
2020
"""Simple polar code for testing."""
2121
decoder_class = SimpleDecoder
2222

23-
def get_decoder(self):
23+
def init_decoder(self):
2424
return self.decoder_class(
2525
n=self.n, mask=self.mask, is_systematic=self.is_systematic
2626
)
2727

2828

29-
class SimplePCCRC(BasicPolarCodeWithCRC):
29+
class SimplePCCRC(BaseCRCPolarCodec):
3030
"""Simple polar code with CRC support for testing."""
3131
decoder_class = SimpleDecoder
3232

33-
def get_decoder(self):
33+
def init_decoder(self):
3434
return self.decoder_class(
3535
n=self.n, mask=self.mask, is_systematic=self.is_systematic
3636
)

python_polar_coding/tests/test_basic_polar_code.py

Lines changed: 0 additions & 124 deletions
This file was deleted.

python_polar_coding/tests/test_sc/__init__.py

Whitespace-only changes.

python_polar_coding/tests/test_sc_decoder.py renamed to python_polar_coding/tests/test_sc/test_decoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import numpy as np
44

5-
from python_polar_coding.polar_codes.decoders import SCDecoder
5+
from python_polar_coding.polar_codes.sc import SCDecoder
66

77

88
class TestSCDecoder(TestCase):

0 commit comments

Comments
 (0)