@@ -30,12 +30,13 @@ def add_v_node(self, ordering_key: int, name: str = "", channel_model: Optional[
3030 self .v_nodes [node .uid ] = node
3131 return node
3232
33- def add_c_node (self , name : str = "" , ordering_key : Optional [int ] = None ) -> CNode :
33+ def add_c_node (self , name : str = "" , ordering_key : Optional [int ] = None , decoder : Optional [ str ] = "BP" ) -> CNode :
3434 """
3535 :param ordering_key: use only for debug purposes
3636 :param name: name of node
37+ :param decoder: must be either "BP" or "MS" for min-sum decoder
3738 """
38- node = CNode (name , ordering_key )
39+ node = CNode (name , ordering_key , decoder = decoder )
3940 self .c_nodes [node .uid ] = node
4041 return node
4142
@@ -68,10 +69,10 @@ def add_edges_by_name(self, edges_set: set[tuple[str, str]]) -> None:
6869 for v_name , c_name in edges_set :
6970 v_uid = [node .uid for node in self .v_nodes .values () if node .name == v_name ]
7071 if not v_uid :
71- raise ValueError ("No v-node with name " + v_name + " in graph" )
72+ raise ValueError (f "No v-node with name { v_name } in graph" )
7273 c_uid = [node .uid for node in self .c_nodes .values () if node .name == c_name ]
7374 if not c_uid :
74- raise ValueError ("No c-node with name " + c_name + " in graph" )
75+ raise ValueError (f "No c-node with name { c_name } in graph" )
7576 self .add_edge (v_uid [0 ], c_uid [0 ])
7677
7778 def get_edges (self , by_name : bool = False ) -> Union [set [tuple [str , str ]], EdgesSet ]:
@@ -94,12 +95,14 @@ def to_nx(self) -> nx.Graph:
9495 return g
9596
9697 @classmethod
97- def from_biadjacency_matrix (cls , h : npt .ArrayLike , channel_model : Optional [ChannelModel ] = None ) -> TannerGraph :
98+ def from_biadjacency_matrix (cls , h : npt .ArrayLike , channel_model : Optional [ChannelModel ] = None ,
99+ decoder : Optional [str ] = "BP" ) -> TannerGraph :
98100 """
99101 Creates a Tanner Graph from a biadjacency matrix, nodes are ordered according to matrix indices.
100102
101103 :param channel_model: channel model to compute channel symbols llr within v nodes
102104 :param h: parity check matrix, shape MXN with M check nodes and N variable nodes. assumed binary matrix.
105+ :param decoder: must be either "BP" or "MS" for min-sum decoder
103106 """
104107 g = TannerGraph ()
105108 h = np .array (h )
@@ -109,7 +112,7 @@ def from_biadjacency_matrix(cls, h: npt.ArrayLike, channel_model: Optional[Chann
109112 v_uid = g .add_v_node (name = f"v{ i } " , channel_model = channel_model , ordering_key = i ).uid
110113 ordered_vnode_uid [i ] = v_uid
111114 for j in range (m ):
112- c_uid = g .add_c_node (name = f"c{ j } " , ordering_key = j ).uid
115+ c_uid = g .add_c_node (name = f"c{ j } " , ordering_key = j , decoder = decoder ).uid
113116 for i in range (n ):
114117 if h [j , i ] == 1 :
115118 g .add_edge (ordered_vnode_uid [i ], c_uid )
0 commit comments