LinearEncoder#
- class sionna.phy.fec.linear.LinearEncoder(enc_mat: numpy.ndarray, *, is_pcm: bool = False, precision: str | None = None, device: str | None = None, **kwargs)[source]#
Bases:
sionna.phy.block.BlockLinear binary encoder for a given generator or parity-check matrix.
If
is_pcmis True,enc_matis interpreted as parity-check matrix and internally converted to a corresponding generator matrix.- Parameters:
enc_mat (numpy.ndarray) – Binary generator matrix of shape [k, n]. If
is_pcmis True,enc_matis interpreted as parity-check matrix of shape [n-k, n].is_pcm (bool) – If True, the
enc_matis interpreted as parity-check matrix instead of a generator matrix.precision (str | None) – Precision used for internal calculations and outputs. If None,
precisionis used.device (str | None) – Device for computation (e.g., ‘cpu’, ‘cuda:0’). If None,
deviceis used.
- Inputs:
info_bits – […, k], torch.float or torch.int. Binary tensor containing the information bits.
- Outputs:
c – […, n], same dtype as
info_bits. Binary tensor containing codewords with same shape as inputs, except the last dimension changes to […, n].
Notes
If
is_pcmis True, this block usespcm2gm()to find the generator matrix for encoding. Please note that this imposes a few constraints on the provided parity-check matrix such as full rank and it must be binary.Note that this encoder is generic for all binary linear block codes and, thus, cannot implement any code specific optimizations. As a result, the encoding complexity is \(O(k^2)\). Please consider code specific encoders such as the
Polar5GEncoderorLDPC5GEncoderfor an improved encoding performance.Examples
import torch from sionna.phy.fec.utils import load_parity_check_examples from sionna.phy.fec.linear import LinearEncoder # Load (7,4) Hamming code pcm, k, n, _ = load_parity_check_examples(0) encoder = LinearEncoder(pcm, is_pcm=True) # Generate random information bits u = torch.randint(0, 2, (10, k), dtype=torch.float32) c = encoder(u) print(c.shape) # torch.Size([10, 7])
Attributes
- property gm: torch.Tensor#
Generator matrix used for encoding.
Methods