[−][src]Struct ldpc::LinearCode
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.
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_the_same_codespace_as(&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_as
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]
pub fn from_parity_check_matrix(matrix: SparseBinMat) -> Self
[src]
Creates a new linear code from the given parity check matrix.
Example
// 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.block_size(), 3); assert_eq!(code.dimension(), 1); assert_eq!(code.minimal_distance(), Some(3));
pub fn from_generator_matrix(matrix: SparseBinMat) -> Self
[src]
Creates a new linear code from the given generator matrix.
Example
// 3 bits repetition code. let matrix = SparseBinMat::new(3, vec![vec![0, 1, 2]]); let code = LinearCode::from_generator_matrix(matrix); assert_eq!(code.block_size(), 3); assert_eq!(code.dimension(), 1); assert_eq!(code.minimal_distance(), Some(3));
pub fn random_regular_code() -> RandomRegularCode
[src]
Returns a builder for random LDPC codes with regular parity check matrix.
Example
use rand::thread_rng; let code = LinearCode::random_regular_code() .block_size(20) .number_of_checks(15) .bit_degree(3) .check_degree(4) .sample_with(&mut thread_rng()); assert_eq!(code.block_size(), 20); assert_eq!(code.number_of_checks(), 15); assert_eq!(code.parity_check_matrix().number_of_ones(), 60);
pub fn parity_check_matrix(&self) -> &SparseBinMat
[src]
Returns the parity check matrix of the code.
pub fn generator_matrix(&self) -> &SparseBinMat
[src]
Returns the generator matrix of the code.
pub fn has_the_same_codespace_as(&self, other: &Self) -> bool
[src]
Checks if two code define the same codespace.
Two codes have the same codespace if all there codewords are the same.
Example
// 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_the_same_codespace_as(&other_hamming_code));
pub fn block_size(&self) -> usize
[src]
Returns the number of bits in the code.
pub fn number_of_checks(&self) -> usize
[src]
Returns the number of rows of the parity check matrix of the code.
pub fn number_of_generators(&self) -> usize
[src]
Returns the number of rows of the generator matrix of the code.
pub fn dimension(&self) -> usize
[src]
Returns the number of linearly independent codewords.
Example
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]
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 syndrome_of(&self, error: &SparseBinSlice<'_>) -> SparseBinVec
[src]
Returns the product of the parity check matrix with the given error.
Example
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 syndrome = SparseBinVec::new(3, vec![0, 1]); assert_eq!(hamming_code.syndrome_of(&error.as_view()), syndrome);
pub fn has_codeword(&self, operator: &SparseBinSlice<'_>) -> bool
[src]
Checks if an operator has zero syndrome.
Example
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.as_view()), false); assert_eq!(hamming_code.has_codeword(&codeword.as_view()), true);
pub fn random_error<N, R>(&self, noise_model: &N, rng: &mut R) -> SparseBinVec where
N: NoiseModel<Error = SparseBinVec>,
R: Rng,
[src]
N: NoiseModel<Error = SparseBinVec>,
R: Rng,
Generates a random error with the given noise model.
Example
use ldpc::noise_model::BinarySymmetricChannel; 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(0.25); let error = code.random_error(&noise, &mut thread_rng()); assert_eq!(error.len(), 7);
Trait Implementations
impl Clone for LinearCode
[src]
pub fn clone(&self) -> LinearCode
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for LinearCode
[src]
impl Eq for LinearCode
[src]
impl Hash for LinearCode
[src]
pub fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl PartialEq<LinearCode> for LinearCode
[src]
pub fn eq(&self, other: &LinearCode) -> bool
[src]
pub fn ne(&self, other: &LinearCode) -> bool
[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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,