[−][src]Struct believer::parity_check_matrix::ParityCheckMatrix
A sparse implementation of a parity check matrix.
Methods
impl ParityCheckMatrix
[src]
pub fn new() -> Self
[src]
Creates an empty parity check matrix. That is, a parity check with 0 bit and 0 check.
Example
use believer::ParityCheckMatrix; let matrix = ParityCheckMatrix::new();
pub fn with_n_bits(n_bits: usize) -> Self
[src]
Creates a new ParityCheckMatrix
with n_bits
and no checks.
Example
use believer::ParityCheckMatrix; let matrix = ParityCheckMatrix::with_n_bits(5);
pub fn with_checks(self, checks: Vec<Check>) -> Self
[src]
Set the checks of self
consuming checks
.
Panic
Panics if some checks are out of bounds. That is, if they are connected to a bit that is
greater or equal than self.get_n_bits()
.
Example
use believer::ParityCheckMatrix; let checks = vec![vec![0, 1], vec![1, 2]]; let mut matrix = ParityCheckMatrix::with_n_bits(3).with_checks(checks);
pub fn identity_with_n_bits(n_bits: usize) -> ParityCheckMatrix
[src]
Creates the n_bits
identity matrix.
Example
use believer::ParityCheckMatrix; let matrix = ParityCheckMatrix::identity_with_n_bits(3); let identity_checks = vec![vec![0], vec![1], vec![2]]; let identity_matrix = ParityCheckMatrix::with_n_bits(3) .with_checks(identity_checks); assert_eq!(matrix, identity_matrix);
pub fn get_n_bits(&self) -> usize
[src]
Returns the number of bits in self
.
pub fn get_n_checks(&self) -> usize
[src]
Returns the number of checks in self
.
pub fn get_n_edges(&self) -> usize
[src]
Returns the number of edges in self
.
pub fn get_bit_degrees(&self) -> Vec<usize>
[src]
Returns the degree of each bit in self
.
Example
use believer::ParityCheckMatrix; let checks = vec![vec![0, 1, 2, 5], vec![1, 3, 4], vec![2, 4, 5], vec![0, 5]]; let matrix = ParityCheckMatrix::with_n_bits(7).with_checks(checks); assert_eq!(matrix.get_bit_degrees(), vec![2, 2, 2, 1, 2, 3, 0]);
pub fn get_check_degrees(&self) -> Vec<usize>
[src]
Returns the degree of each check in self
.
Example
use believer::ParityCheckMatrix; let checks = vec![vec![0, 1, 2, 5], vec![1, 3, 4], vec![2, 4, 5], vec![0, 5]]; let matrix = ParityCheckMatrix::with_n_bits(7).with_checks(checks); assert_eq!(matrix.get_check_degrees(), vec![4, 3, 3, 2]);
pub fn get_check(&self, check: usize) -> Option<CheckView>
[src]
Returns Some
view over the given check
in self
. Returns None
if
check
is out of bound.
Example
use believer::ParityCheckMatrix; let checks = vec![vec![0, 1], vec![1, 2]]; let parity_check = ParityCheckMatrix::with_n_bits(3).with_checks(checks); let check = parity_check.get_check(0).unwrap(); assert_eq!(check.as_ref(), &[0, 1]); let check = parity_check.get_check(1).unwrap(); assert_eq!(check.as_ref(), &[1, 2]); assert!(parity_check.get_check(2).is_none());
pub fn get_syndrome_of(&self, message: &[GF2]) -> Vec<GF2>
[src]
Computes the syndrome of a given message
.
Example
use believer::{GF2, ParityCheckMatrix}; let checks = vec![vec![0, 1], vec![1, 2]]; let parity_check = ParityCheckMatrix::with_n_bits(3).with_checks(checks); let message = vec![GF2::B0, GF2::B1, GF2::B1]; assert_eq!(parity_check.get_syndrome_of(&message), vec![GF2::B1, GF2::B0]);
pub fn get_rank(&self) -> usize
[src]
Computes the rank of self
.
Example
use believer::ParityCheckMatrix; let checks = vec![vec![0, 1], vec![1, 2], vec![0, 2]]; let parity_check = ParityCheckMatrix::with_n_bits(3).with_checks(checks); assert_eq!(parity_check.get_rank(), 2);
pub fn get_transposed_matrix(&self) -> Self
[src]
Gets the transposed version of self
by swapping the bits with the checks.
Example
use believer::ParityCheckMatrix; let checks = vec![vec![0, 1, 2], vec![1, 3], vec![0, 2, 3]]; let matrix = ParityCheckMatrix::with_n_bits(4).with_checks(checks); let transposed_matrix = matrix.get_transposed_matrix(); let expected_checks = vec![vec![0, 2], vec![0, 1], vec![0, 2], vec![1, 2]]; let expected_matrix = ParityCheckMatrix::with_n_bits(3).with_checks(expected_checks); assert_eq!(transposed_matrix, expected_matrix);
pub fn get_horizontal_concat_with(
&self,
other: &ParityCheckMatrix
) -> ParityCheckMatrix
[src]
&self,
other: &ParityCheckMatrix
) -> ParityCheckMatrix
Returns the horizontal concatenation of self
with other
.
Example
use believer::ParityCheckMatrix; let left_matrix = ParityCheckMatrix::with_n_bits(3) .with_checks(vec![vec![0, 1], vec![1, 2]]); let right_matrix = ParityCheckMatrix::with_n_bits(4) .with_checks(vec![vec![1, 2, 3], vec![0, 1], vec![2, 3]]); let concatened = left_matrix.get_horizontal_concat_with(&right_matrix); let expected = ParityCheckMatrix::with_n_bits(7) .with_checks(vec![vec![0, 1, 4, 5, 6], vec![1, 2, 3, 4], vec![5, 6]]); assert_eq!(concatened, expected);
pub fn get_diagonal_concat_with(
&self,
other: &ParityCheckMatrix
) -> ParityCheckMatrix
[src]
&self,
other: &ParityCheckMatrix
) -> ParityCheckMatrix
Returns the diagonal concatenation of self
with other
.
Example
use believer::ParityCheckMatrix; let left_matrix = ParityCheckMatrix::with_n_bits(3) .with_checks(vec![vec![0, 1], vec![1, 2]]); let right_matrix = ParityCheckMatrix::with_n_bits(4) .with_checks(vec![vec![1, 2, 3], vec![0, 1], vec![2, 3]]); let concatened = left_matrix.get_diagonal_concat_with(&right_matrix); let expected = ParityCheckMatrix::with_n_bits(7) .with_checks(vec![vec![0, 1], vec![1, 2], vec![4, 5, 6], vec![3, 4], vec![5, 6]]); assert_eq!(concatened, expected);
ⓘImportant traits for ChecksIter<'a>pub fn checks_iter(&self) -> ChecksIter
[src]
Returns an iterator that yields a slice for each check of self
.
Example
use believer::ParityCheckMatrix; let parity_check = ParityCheckMatrix::with_n_bits(3) .with_checks(vec![vec![0, 1], vec![1, 2]]); let mut iter = parity_check.checks_iter(); assert_eq!(iter.next(), parity_check.get_check(0)); assert_eq!(iter.next(), parity_check.get_check(1)); assert_eq!(iter.next(), None);
ⓘImportant traits for EdgesIter<'a>pub fn edges_iter(&self) -> EdgesIter
[src]
An iterators over all edges in self
ordered by check first.
Example
let parity_check = ParityCheckMatrix::with_n_bits(3) .with_checks(vec![vec![0, 1], vec![1, 2]]); let mut iter = parity_check.edges_iter(); assert_eq!(iter.next(), Some((0, 0))); assert_eq!(iter.next(), Some((0, 1))); assert_eq!(iter.next(), Some((1, 1))); assert_eq!(iter.next(), Some((1, 2))); assert_eq!(iter.next(), None);
pub fn has_codeword(&self, message: &[GF2]) -> bool
[src]
Checks if a given message
is a codeword of self
.
Example
use believer::{GF2, ParityCheckMatrix}; let parity_check = ParityCheckMatrix::with_n_bits(3) .with_checks(vec![vec![0, 1], vec![1, 2]]); let message = vec![GF2::B0, GF2::B1, GF2::B1]; let codeword = vec![GF2::B0; 3]; assert_eq!(parity_check.has_codeword(&message), false); assert_eq!(parity_check.has_codeword(&codeword), true);
pub fn keep(&self, bits: &[usize]) -> Self
[src]
Returns a truncated parity check matrix with only the column of the given bits
.
Example
use believer::ParityCheckMatrix; let checks = ParityCheckMatrix::with_n_bits(5).with_checks(vec![ vec![0, 1, 2], vec![2, 3, 4], vec![0, 2, 4], vec![1, 3], ]); let truncated_checks = ParityCheckMatrix::with_n_bits(5).with_checks(vec![ vec![0, 1], vec![4], vec![0, 4], vec![1], ]); assert_eq!(checks.keep(&[0, 1, 4]), truncated_checks);
pub fn without(&self, bits: &[usize]) -> Self
[src]
Returns a truncated parity check matrix where the column of the given bits
are remove.
Example
let checks = ParityCheckMatrix::with_n_bits(5).with_checks(vec![ vec![0, 1, 2], vec![2, 3, 4], vec![0, 2, 4], vec![1, 3], ]); let truncated_checks = ParityCheckMatrix::with_n_bits(5).with_checks(vec![ vec![1], vec![3, 4], vec![4], vec![1, 3], ]); assert_eq!(checks.without(&[0, 2]), truncated_checks);
pub fn gbc(&self, b: &ParityCheckMatrix) -> ParityCheckMatrix
[src]
pub fn permu_matrix(l: usize) -> ParityCheckMatrix
[src]
pub fn circulant_down(indices: &Vec<usize>, l: usize) -> ParityCheckMatrix
[src]
pub fn circulant_right(indices: &Vec<usize>, l: usize) -> ParityCheckMatrix
[src]
Trait Implementations
impl Clone for ParityCheckMatrix
[src]
fn clone(&self) -> ParityCheckMatrix
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl PartialEq<ParityCheckMatrix> for ParityCheckMatrix
[src]
fn eq(&self, other: &ParityCheckMatrix) -> bool
[src]
fn ne(&self, other: &ParityCheckMatrix) -> bool
[src]
impl Debug for ParityCheckMatrix
[src]
impl Display for ParityCheckMatrix
[src]
impl StructuralPartialEq for ParityCheckMatrix
[src]
Auto Trait Implementations
impl Send for ParityCheckMatrix
impl Sync for ParityCheckMatrix
impl Unpin for ParityCheckMatrix
impl UnwindSafe for ParityCheckMatrix
impl RefUnwindSafe for ParityCheckMatrix
Blanket Implementations
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.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
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.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,