Skip to main content

LdpcCode

Struct LdpcCode 

Source
pub struct LdpcCode {
    pub decoder: LdpcDecoder,
    /* private fields */
}
Expand description

An LDPC code with its systematic encoder and its decoder settings.

Fields§

§decoder: LdpcDecoder

The decoder settings.

Implementations§

Source§

impl LdpcCode

Source

pub fn from_rows(n: usize, rows: Vec<Vec<usize>>) -> Result<LdpcCode>

The code of the parity-check matrix whose rows list the variable nodes of every check; $k = n - \operatorname{rank} H$.

§Errors

Error::Config for a variable index out of range or a code without information bits.

Source

pub fn without_encoder( n: usize, rows: Vec<Vec<usize>>, info: Vec<usize>, ) -> Result<LdpcCode>

The code of the parity-check matrix rows whose information bits are at the positions info, without an encoder of its own: its decoder only (LdpcCode::decode_llr, BlockCode::decode_block), for a code whose standard gives the encoder (the LDPC codes of crate::ccsds, whose systematic generators LdpcCode::from_rows would store densely). BlockCode::encode_block returns an error.

§Errors

Error::Config for a variable index out of range, or information positions out of range, repeated or absent.

Source

pub fn accumulate(n: usize, rows: Vec<Vec<usize>>) -> Result<LdpcCode>

An irregular repeat-accumulate code: check $r$ of rows holds information bits (positions below $k = n - m$, $m$ the number of checks) and the parity bits $k + r$ and, for $r > 0$, $k + r - 1$ only (the dual-diagonal structure of the DVB-S2, DVB-T2 and IEEE 802.11n codes). The encoder accumulates the checks, in $O(n)$, without the elimination of LdpcCode::from_rows.

§Errors

Error::Config if the checks do not have this structure.

Source

pub fn from_core_rows( n: usize, rows: Vec<Vec<usize>>, k: usize, core: usize, ) -> Result<LdpcCode>

A code whose $m$ checks have a core and an extension, the structure of the LDPC codes of 5G NR (TS 38.212, Sec. 5.3.2): the information bits are the first $k$; the first core checks involve the bits below $k + \mathrm{core}$ only, with an invertible square block on the core parity bits $k, \dots, k + \mathrm{core} - 1$; every other check $r$ contains the parity bit $k + r$ and no bit above it. The encoder inverts the core block once, by Gauss–Jordan elimination over GF(2), then computes the extension parity bits one after the other, without the elimination of the whole matrix of LdpcCode::from_rows.

§Errors

Error::Config if the checks do not have this structure or the core block is singular.

Source

pub fn peg(n: usize, k: usize, var_degree: usize, seed: u64) -> Result<LdpcCode>

A code of length n with n - k checks built by progressive edge growth, every variable node of degree var_degree (seeded tie breaks).

§Errors

Error::Config for $k \ge n$ or a degree larger than the number of checks.

Source

pub fn from_alist(text: &str) -> Result<LdpcCode>

The code of a parity-check matrix written in MacKay’s alist format (the format of MacKay’s Encyclopedia of Sparse Graph Codes and of the matrices shipped with AFF3CT), with the systematic encoder of LdpcCode::from_rows. The rows of $H$ keep the order of the file, which is the order of a layered schedule.

The format is a list of integers: $n$ and $m$ (columns and rows of $H$), the largest column and row degrees, the $n$ column degrees, the $m$ row degrees, then for every column the (1-based) rows of its ones, and for every row the columns of its ones. The lists may be padded with zeros up to the largest degree or not; the text after a # is a comment. The two descriptions of the matrix must agree.

§Errors

Error::Config for a malformed file: a missing or extra number, a degree or an index out of range, a repeated one, or column and row lists that disagree; or for a matrix that LdpcCode::from_rows rejects.

§Examples
use comnum_fec::block::BlockCode;
use comnum_fec::ldpc::LdpcCode;
// the (7, 4) Hamming code: n = 7 columns, m = 3 rows
let alist = "7 3\n3 4\n3 2 2 2 1 1 1\n4 4 4\n\
             1 2 3\n1 2 0\n1 3 0\n2 3 0\n1 0 0\n2 0 0\n3 0 0\n\
             1 2 3 5\n1 2 4 6\n1 3 4 7\n";
let code = LdpcCode::from_alist(alist)?;
assert_eq!((code.n(), code.k()), (7, 4));
assert_eq!(code.rows()[1], [0, 1, 3, 5]);
assert_eq!(LdpcCode::from_alist(&code.to_alist())?, code);
§References
  1. D. J. C. MacKay, Encyclopedia of Sparse Graph Codes, “alist” format, http://www.inference.org.uk/mackay/codes/alist.html.
Source

pub fn from_alist_file(path: impl AsRef<Path>) -> Result<LdpcCode>

LdpcCode::from_alist on the content of the file path.

§Errors

Error::Io if the file cannot be read, otherwise those of LdpcCode::from_alist.

Source

pub fn to_alist(&self) -> String

The parity-check matrix in the alist format of LdpcCode::from_alist, with the lists padded with zeros (the format MacKay’s files use).

Source

pub fn info_positions(&self) -> &[usize]

The positions of the information bits in the codeword, in the order of the information bits of BlockCode::encode_block (the code is systematic).

Source

pub fn rows(&self) -> &[Vec<usize>]

The parity checks: the variable nodes of every row of $H$.

Source

pub fn is_codeword(&self, c: &[u8]) -> bool

Whether $H c = 0$.

Source

pub fn girth(&self) -> usize

The length of the shortest cycle through every variable node of the Tanner graph, minimised over the graph (the girth; 0 without cycle).

Source

pub fn decode_llr(&self, llr: &[f64]) -> Result<(Vec<f64>, usize)>

Decode a block of $n$ channel LLRs: the a posteriori LLRs of the coded bits and the number of iterations used.

§Errors

Error::Shape if llr does not have $n$ values.

Trait Implementations§

Source§

impl BlockCode for LdpcCode

Source§

fn encode_block(&self, info: &[u8]) -> Result<Vec<u8>>

§Errors

Error::Shape unless info has $k$ bits; Error::Config for a code built by LdpcCode::without_encoder.

Source§

fn k(&self) -> usize

Information bits per block.
Source§

fn n(&self) -> usize

Coded bits per block.
Source§

fn decode_block(&self, llr: &[f64]) -> Result<Vec<u8>>

Decode one block of $n$ LLRs into $k$ bits. Read more
Source§

fn encode_block_into(&self, info: &[u8], out: &mut [u8]) -> Result<()>

Encode one block of $k$ bits into the $n$ values of out (ADR 0011: the default copies BlockCode::encode_block; a code overrides it when a profile shows the copy). Read more
Source§

fn decode_block_into(&self, llr: &[f64], out: &mut [u8]) -> Result<()>

Decode one block of $n$ LLRs into the $k$ values of out (as BlockCode::encode_block_into). Read more
Source§

fn code_rate(&self) -> f64

Code rate $k/n$.
Source§

fn encode_stream(&self, info: &[u8]) -> Result<Vec<u8>>

Encode whole blocks. Read more
Source§

fn decode_stream(&self, llr: &[f64]) -> Result<Vec<u8>>

Decode whole blocks. Read more
Source§

impl Clone for LdpcCode

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LdpcCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Decode for LdpcCode

Source§

fn decode_into(&mut self, llr: &Llr, out: &mut Bits) -> Result<()>

Decode llr into out. Read more
Source§

fn decode(&mut self, llr: &Llr) -> Result<Bits, Error>

Decode llr (allocates, calls Decode::decode_into). Read more
Source§

impl Encode for LdpcCode

Source§

fn rate(&self) -> f64

Code rate k/n.
Source§

fn encode_into(&self, info: &Bits, out: &mut Bits) -> Result<()>

Encode info into out. Read more
Source§

fn encode(&self, info: &Bits) -> Result<Bits, Error>

Encode info (allocates, calls Encode::encode_into). Read more
Source§

impl PartialEq for LdpcCode

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl SoftDecode for LdpcCode

Source§

fn app_into( &self, llr: &[f64], apriori: Option<&[f64]>, out: &mut [f64], ) -> Result<usize>

The a posteriori LLRs of the information bits of LdpcCode::decode_llr; the a priori LLRs add to the channel LLRs of the information positions.

Source§

fn app(&self, llr: &[f64], apriori: Option<&[f64]>) -> Result<Vec<f64>>

SoftDecode::app_into into a new vector. Read more
Source§

impl StructuralPartialEq for LdpcCode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.