Struct ldpc::classical::LinearCode [−][src]
pub struct LinearCode { /* fields omitted */ }
Expand description
An implementation of linear codes optimized for LDPC codes.
A code can be define from either a parity check matrix H
or a generator matrix G
.
These matrices have the property that H G^T = 0
.
Example
This is example shows 2 way to define the Hamming code.
use sparse_bin_mat::SparseBinMat; let parity_check_matrix = SparseBinMat::new( 7, vec![vec![0, 1, 2, 4], vec![0, 1, 3, 5], vec![0, 2, 3, 6]] ); let generator_matrix = SparseBinMat::new( 7, vec![vec![0, 4, 5, 6], vec![1, 4, 5], vec![2, 4, 6], vec![3, 5, 6]] ); let code_from_parity = LinearCode::from_parity_check_matrix(parity_check_matrix); let code_from_generator = LinearCode::from_generator_matrix(generator_matrix); assert!(code_from_parity.has_same_codespace(&code_from_generator));
Comparison
Use the ==
if you want to know if 2 codes
have exactly the same parity check matrix and
generator matrix.
However, since there is freedom in the choice of
parity check matrix and generator matrix for the same code,
use has_the_same_codespace
method
if you want to know if 2 codes define the same codespace even
if they may have different parity check matrix or generator matrix.
Implementations
impl LinearCode
[src]
impl LinearCode
[src]pub fn from_parity_check_matrix(parity_check_matrix: SparseBinMat) -> Self
[src]
pub fn from_parity_check_matrix(parity_check_matrix: SparseBinMat) -> Self
[src]Creates a new linear code from the given parity check matrix.
Example
use sparse_bin_mat::SparseBinMat; // 3 bits repetition code. let matrix = SparseBinMat::new(3, vec![vec![0, 1], vec![1, 2]]); let code = LinearCode::from_parity_check_matrix(matrix); assert_eq!(code.len(), 3); assert_eq!(code.dimension(), 1); assert_eq!(code.minimal_distance(), Some(3));
pub fn from_generator_matrix(generator_matrix: SparseBinMat) -> Self
[src]
pub fn from_generator_matrix(generator_matrix: SparseBinMat) -> Self
[src]Creates a new linear code from the given generator matrix.
Example
use sparse_bin_mat::SparseBinMat; // 3 bits repetition code. let matrix = SparseBinMat::new(3, vec![vec![0, 1, 2]]); let code = LinearCode::from_generator_matrix(matrix); assert_eq!(code.len(), 3); assert_eq!(code.dimension(), 1); assert_eq!(code.minimal_distance(), Some(3));
pub fn repetition_code(length: usize) -> Self
[src]
pub fn repetition_code(length: usize) -> Self
[src]Returns a repetition code with the given length.
Example
use sparse_bin_mat::SparseBinMat; let matrix = SparseBinMat::new(3, vec![vec![0, 1], vec![1, 2]]); let code = LinearCode::from_parity_check_matrix(matrix); assert!(code.has_same_codespace(&LinearCode::repetition_code(3)));
pub fn hamming_code() -> Self
[src]
pub fn hamming_code() -> Self
[src]Returns the Hamming code.
Example
use sparse_bin_mat::SparseBinMat; let matrix = SparseBinMat::new( 7, vec![vec![3, 4, 5, 6], vec![1, 2, 5, 6], vec![0, 2, 4, 6]], ); let code = LinearCode::from_parity_check_matrix(matrix); assert!(code.has_same_codespace(&LinearCode::hamming_code()));
pub fn empty() -> Self
[src]
pub fn empty() -> Self
[src]Returns a code of length 0 encoding 0 bits and without checks.
This is mostly useful as a place holder.
pub fn random_regular_code() -> RandomRegularCode
[src]
pub fn random_regular_code() -> RandomRegularCode
[src]Returns a builder for random LDPC codes with regular parity check matrix.
The sample_with
method returns
an error if the number of bits times the bit’s degree is not equal
to the number of checks times the bit check’s degree.
Example
use rand::thread_rng; let code = LinearCode::random_regular_code() .num_bits(20) .num_checks(15) .bit_degree(3) .check_degree(4) .sample_with(&mut thread_rng()) .unwrap(); // 20 * 3 == 15 * 4 assert_eq!(code.len(), 20); assert_eq!(code.num_checks(), 15); assert_eq!(code.parity_check_matrix().number_of_ones(), 60);
pub fn parity_check_matrix(&self) -> &SparseBinMat
[src]
pub fn parity_check_matrix(&self) -> &SparseBinMat
[src]Returns the parity check matrix of the code.
pub fn check(&self, index: usize) -> Option<SparseBinSlice<'_>>
[src]
pub fn check(&self, index: usize) -> Option<SparseBinSlice<'_>>
[src]Returns the check at the given index or None if the index is out of bound.
That is, this returns the row of the parity check matrix with the given index.
pub fn generator_matrix(&self) -> &SparseBinMat
[src]
pub fn generator_matrix(&self) -> &SparseBinMat
[src]Returns the generator matrix of the code.
pub fn generator(&self, index: usize) -> Option<SparseBinSlice<'_>>
[src]
pub fn generator(&self, index: usize) -> Option<SparseBinSlice<'_>>
[src]Returns the generator at the given index or None if the index is out of bound.
That is, this returns the row of the generator matrix with the given index.
pub fn bit_adjacencies(&self) -> &SparseBinMat
[src]
pub fn bit_adjacencies(&self) -> &SparseBinMat
[src]Returns a matrix where the value in row i correspond to the check connected to bit i.
pub fn checks_adjacent_to_bit(&self, bit: usize) -> Option<SparseBinSlice<'_>>
[src]
pub fn checks_adjacent_to_bit(&self, bit: usize) -> Option<SparseBinSlice<'_>>
[src]Returns the checks adjacents to the given bit or None if the bit is out of bound.
pub fn has_same_codespace(&self, other: &Self) -> bool
[src]
pub fn has_same_codespace(&self, other: &Self) -> bool
[src]Checks if two code define the same codespace.
Two codes have the same codespace if all their codewords are the same.
Example
use sparse_bin_mat::SparseBinMat; // The Hamming code let parity_check_matrix = SparseBinMat::new( 7, vec![vec![0, 1, 2, 4], vec![0, 1, 3, 5], vec![0, 2, 3, 6]] ); let hamming_code = LinearCode::from_parity_check_matrix(parity_check_matrix); // Same but with the add the first check to the other two. let parity_check_matrix = SparseBinMat::new( 7, vec![vec![0, 1, 2, 4], vec![2, 3, 4, 5], vec![1, 3, 4, 6]] ); let other_hamming_code = LinearCode::from_parity_check_matrix(parity_check_matrix); assert!(hamming_code.has_same_codespace(&other_hamming_code));
pub fn num_checks(&self) -> usize
[src]
pub fn num_checks(&self) -> usize
[src]Returns the number of rows of the parity check matrix of the code.
pub fn num_generators(&self) -> usize
[src]
pub fn num_generators(&self) -> usize
[src]Returns the number of rows of the generator matrix of the code.
pub fn dimension(&self) -> usize
[src]
pub fn dimension(&self) -> usize
[src]Returns the number of linearly independent codewords.
Example
use sparse_bin_mat::SparseBinMat; let parity_check_matrix = SparseBinMat::new( 7, vec![vec![0, 1, 2, 4], vec![0, 1, 3, 5], vec![0, 2, 3, 6]] ); let hamming_code = LinearCode::from_parity_check_matrix(parity_check_matrix); assert_eq!(hamming_code.dimension(), 4);
pub fn minimal_distance(&self) -> Option<usize>
[src]
pub fn minimal_distance(&self) -> Option<usize>
[src]Returns the weight of the smallest non trivial codeword or None if the code have no codeword.
Warning
The execution time of this method scale exponentially with the dimension of the code.
pub fn edges(&self) -> Edges<'_>ⓘ
[src]
pub fn edges(&self) -> Edges<'_>ⓘ
[src]Returns an iterator over all edges of the Tanner graph associated with the parity check matrix of the code.
That is, this returns an iterator of over the coordinates (i, j) such that H_ij = 1 with H the parity check matrix.
Example
use ldpc::classical::Edge; use sparse_bin_mat::{SparseBinMat, SparseBinVec}; let parity_check_matrix = SparseBinMat::new( 4, vec![vec![0, 1], vec![0, 3], vec![1, 2]] ); let code = LinearCode::from_parity_check_matrix(parity_check_matrix); let mut edges = code.edges(); assert_eq!(edges.next(), Some(Edge { bit: 0, check: 0})); assert_eq!(edges.next(), Some(Edge { bit: 1, check: 0})); assert_eq!(edges.next(), Some(Edge { bit: 0, check: 1})); assert_eq!(edges.next(), Some(Edge { bit: 3, check: 1})); assert_eq!(edges.next(), Some(Edge { bit: 1, check: 2})); assert_eq!(edges.next(), Some(Edge { bit: 2, check: 2})); assert_eq!(edges.next(), None);
pub fn syndrome_of<T>(&self, message: &SparseBinVecBase<T>) -> SparseBinVec where
T: Deref<Target = [usize]>,
[src]
pub fn syndrome_of<T>(&self, message: &SparseBinVecBase<T>) -> SparseBinVec where
T: Deref<Target = [usize]>,
[src]Returns the product of the parity check matrix with the given message
Example
use sparse_bin_mat::{SparseBinMat, SparseBinVec}; let parity_check_matrix = SparseBinMat::new( 7, vec![vec![0, 1, 2, 4], vec![0, 1, 3, 5], vec![0, 2, 3, 6]] ); let hamming_code = LinearCode::from_parity_check_matrix(parity_check_matrix); let message = SparseBinVec::new(7, vec![0, 2, 4]); let syndrome = SparseBinVec::new(3, vec![0, 1]); assert_eq!(hamming_code.syndrome_of(&message.as_view()), syndrome);
Panic
Panics if the message have a different length then the code.
pub fn has_codeword<T>(&self, operator: &SparseBinVecBase<T>) -> bool where
T: Deref<Target = [usize]>,
[src]
pub fn has_codeword<T>(&self, operator: &SparseBinVecBase<T>) -> bool where
T: Deref<Target = [usize]>,
[src]Checks if a message has zero syndrome.
Example
use sparse_bin_mat::{SparseBinMat, SparseBinVec}; let parity_check_matrix = SparseBinMat::new( 7, vec![vec![0, 1, 2, 4], vec![0, 1, 3, 5], vec![0, 2, 3, 6]] ); let hamming_code = LinearCode::from_parity_check_matrix(parity_check_matrix); let error = SparseBinVec::new(7, vec![0, 2, 4]); let codeword = SparseBinVec::new(7, vec![2, 3, 4, 5]); assert_eq!(hamming_code.has_codeword(&error), false); assert_eq!(hamming_code.has_codeword(&codeword), true);
Panic
Panics if the message have a different length then code.
pub fn random_error<N, R>(&self, noise_model: &N, rng: &mut R) -> SparseBinVec where
N: NoiseModel<Error = SparseBinVec>,
R: Rng,
[src]
pub fn random_error<N, R>(&self, noise_model: &N, rng: &mut R) -> SparseBinVec where
N: NoiseModel<Error = SparseBinVec>,
R: Rng,
[src]Generates a random error with the given noise model.
Example
use sparse_bin_mat::SparseBinMat; use ldpc::noise_model::{BinarySymmetricChannel, Probability}; use rand::thread_rng; let parity_check_matrix = SparseBinMat::new( 7, vec![vec![0, 1, 2, 4], vec![0, 1, 3, 5], vec![0, 2, 3, 6]] ); let code = LinearCode::from_parity_check_matrix(parity_check_matrix); let noise = BinarySymmetricChannel::with_probability(Probability::new(0.25)); let error = code.random_error(&noise, &mut thread_rng()); assert_eq!(error.len(), 7);
Trait Implementations
impl Clone for LinearCode
[src]
impl Clone for LinearCode
[src]fn clone(&self) -> LinearCode
[src]
fn clone(&self) -> LinearCode
[src]Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]Performs copy-assignment from source
. Read more
impl Debug for LinearCode
[src]
impl Debug for LinearCode
[src]impl<'de> Deserialize<'de> for LinearCode
[src]
impl<'de> Deserialize<'de> for LinearCode
[src]fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]Deserialize this value from the given Serde deserializer. Read more
impl Hash for LinearCode
[src]
impl Hash for LinearCode
[src]impl PartialEq<LinearCode> for LinearCode
[src]
impl PartialEq<LinearCode> for LinearCode
[src]fn eq(&self, other: &LinearCode) -> bool
[src]
fn eq(&self, other: &LinearCode) -> bool
[src]This method tests for self
and other
values to be equal, and is used
by ==
. Read more
fn ne(&self, other: &LinearCode) -> bool
[src]
fn ne(&self, other: &LinearCode) -> bool
[src]This method tests for !=
.
impl Serialize for LinearCode
[src]
impl Serialize for LinearCode
[src]impl Eq for LinearCode
[src]
impl StructuralEq for LinearCode
[src]
impl StructuralPartialEq for LinearCode
[src]
Auto Trait Implementations
impl RefUnwindSafe for LinearCode
impl Send for LinearCode
impl Sync for LinearCode
impl Unpin for LinearCode
impl UnwindSafe for LinearCode
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]pub fn equivalent(&self, key: &K) -> bool
[src]
pub fn equivalent(&self, key: &K) -> bool
[src]Compare self to key
and return true
if they are equal.
impl<T> Pointable for T
impl<T> Pointable for T
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
pub fn to_subset(&self) -> Option<SS>
pub fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
pub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
pub unsafe fn to_subset_unchecked(&self) -> SS
pub unsafe fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
pub fn from_subset(element: &SS) -> SP
pub fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
pub fn vzip(self) -> V
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,