Skip to content

Commit ae5251c

Browse files
author
grigory
committed
Refactor Fast SCAN codec
1 parent f526f79 commit ae5251c

File tree

2 files changed

+26
-54
lines changed

2 files changed

+26
-54
lines changed
Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,20 @@
1-
from python_polar_coding.polar_codes.rc_scan import (
2-
RCSCANNode,
3-
compute_beta_one_node,
4-
compute_beta_zero_node,
5-
)
1+
from python_polar_coding.polar_codes.rc_scan import RCSCANNode
62

7-
from .functions import compute_repetition_beta, compute_spc_beta
3+
from ..base import NodeTypes
84

95

106
class FastSCANNode(RCSCANNode):
11-
12-
def compute_leaf_beta(self):
13-
"""Compute leaf beta."""
14-
if self.is_repetition:
15-
self.beta = compute_repetition_beta(self.alpha)
16-
if self.is_parity:
17-
self.beta = compute_spc_beta(self.alpha)
18-
19-
def initialize_leaf_beta(self):
20-
"""Initialize BETA values on tree building.
21-
22-
Initialize ZERO and ONE nodes following to Section III
23-
doi:10.1109/jsac.2014.140515
24-
25-
"""
26-
if not self.is_leaf:
27-
return
28-
29-
if self.is_parity or self.is_repetition:
30-
return
31-
32-
if self.is_zero:
33-
self._beta = compute_beta_zero_node(self.alpha)
34-
if self.is_one:
35-
self._beta = compute_beta_one_node(self.alpha)
36-
37-
def get_node_type(self):
38-
"""Get the type of Fast SCAN Node.
39-
40-
* Zero node - [0, 0, 0, 0, 0, 0, 0, 0];
41-
* One node - [1, 1, 1, 1, 1, 1, 1, 1];
42-
* Single parity check node - [0, 1, 1, 1, 1, 1, 1, 1];
43-
* Repetition node - [0, 0, 0, 0, 0, 0, 0, 1].
44-
45-
Or other type.
46-
47-
"""
48-
if self._check_is_zero(self._mask):
49-
return self.ZERO_NODE
50-
if self._check_is_one(self._mask):
51-
return self.ONE_NODE
52-
if self._check_is_rep(self._mask):
53-
return self.REPETITION
54-
if self._check_is_spc(self._mask):
55-
return self.SINGLE_PARITY_CHECK
56-
return self.OTHER
7+
supported_nodes = (
8+
NodeTypes.ZERO,
9+
NodeTypes.ONE,
10+
NodeTypes.REPETITION,
11+
NodeTypes.SINGLE_PARITY_CHECK,
12+
)
13+
14+
@property
15+
def is_repetition(self):
16+
return self.node_type == NodeTypes.REPETITION
17+
18+
@property
19+
def is_parity(self):
20+
return self.node_type == NodeTypes.SINGLE_PARITY_CHECK

python_polar_coding/polar_codes/rc_scan/node.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from typing import Dict
22

3-
from python_polar_coding.polar_codes.base.functions.beta_soft import one, zero
3+
from python_polar_coding.polar_codes.base.functions.beta_soft import (
4+
compute_beta_soft,
5+
one,
6+
zero,
7+
)
48

59
from ..base import NodeTypes, SoftNode
610

@@ -34,11 +38,15 @@ def compute_leaf_beta(self):
3438
in leaves.
3539
3640
"""
41+
if self.is_one or self.is_zero:
42+
return
43+
self.beta = compute_beta_soft(self.node_type, self.alpha)
3744

3845
def initialize_leaf_beta(self):
3946
"""Initialize BETA values on tree building.
4047
41-
Initialize Leaves following to Section III doi:10.1109/jsac.2014.140515
48+
Initialize ZERO and ONE nodes following to Section III
49+
doi:10.1109/jsac.2014.140515
4250
4351
"""
4452
if not self.is_leaf:

0 commit comments

Comments
 (0)