Struct ldpc_toolbox::sparse::SparseMatrix[][src]

pub struct SparseMatrix { /* fields omitted */ }
Expand description

A sparse binary matrix

The internal representation for this matrix is based on the alist format.

Implementations

Create a new sparse matrix of a given size

The matrix is inizialized to the zero matrix.

Examples

let h = SparseMatrix::new(10, 30);
assert_eq!(h.num_rows(), 10);
assert_eq!(h.num_cols(), 30);

Returns the number of rows of the matrix

Returns the number of columns of the matrix

Returns the row weight of row

The row weight is defined as the number of entries equal to one in a particular row. Rows are indexed starting by zero.

Returns the column weight of column

The column weight is defined as the number of entries equal to one in a particular column. Columns are indexed starting by zero.

Returns true if the entry corresponding to a particular row and column is a one

Inserts a one in a particular row and column

Examples

let mut h = SparseMatrix::new(10, 30);
assert!(!h.contains(3, 7));
h.insert(3, 7);
assert!(h.contains(3, 7));

Inserts ones in particular columns of a row

This effect is as calling insert() on each of the elements of the iterator cols.

Examples

let mut h1 = SparseMatrix::new(10, 30);
let mut h2 = SparseMatrix::new(10, 30);
let c = vec![3, 7, 9];
h1.insert_row(0, c.iter());
for a in &c {
    h2.insert(0, *a);
}
assert_eq!(h1, h2);

Inserts ones in a particular rows of a column

This works like insert_row().

Remove all the ones in a particular row

Remove all the ones in a particular column

Set the elements that are equal to one in a row

The effect of this is like calling clear_row() followed by insert_row().

Set the elements that are equal to one in a column

Returns an Iterator over the entries equal to one in a particular row

Returns an Iterator over the entries equal to one in a particular column

Writes the matrix in alist format to a writer

Errors

If a call to write!() returns an error, this function returns such an error.

Returns a String with the alist representation of the matrix

Constructs and returns a sparse matrix from its alist representation

Errors

alist should hold a valid alist representation. If an error is found while parsing alist, a String describing the error will be returned.

Returns the girth of the bipartite graph defined by the matrix

The girth is the length of the shortest cycle. If there are no cycles, None is returned.

Examples

The following shows that a 2 x 2 matrix whose entries are all equal to one has a girth of 4, which is the smallest girth that a bipartite graph can have.

let mut h = SparseMatrix::new(2, 2);
for j in 0..2 {
    for k in 0..2 {
        h.insert(j, k);
    }
}
assert_eq!(h.girth(), Some(4));

Returns the girth of the bipartite graph defined by the matrix as long as it is smaller than a maximum

By imposing a maximum value in the girth search algorithm, the execution time is reduced, since paths longer than the maximum do not need to be explored.

Often it is only necessary to check that a graph has at least some minimum girth, so it is possible to use girth_with_max().

If there are no cycles with length smaller or equal to max, then None is returned.

Returns the local girth at a particular node

The local girth at a node of a graph is defined as the minimum length of the cycles containing that node.

This function returns the local girth of at the node correponding to a column or row of the matrix, or None if there are no cycles containing that node.

Returns the girth at a particular node with a maximum

This function works like girth_at_node() but imposes a maximum in the length of the cycles considered. None is returned if there are no cycles containing the node with length smaller or equal than max.

Run the BFS algorithm

This uses a node of the graph associated to the matrix as the root for the BFS algorithm and finds the distances from each of the nodes of the graph to that root using breadth-first search.

Examples

Run BFS on a matrix that has two connected components.

let mut h = SparseMatrix::new(4, 4);
for j in 0..4 {
    for k in 0..4 {
        if (j % 2) == (k % 2) {
            h.insert(j, k);
        }
    }
}
println!("{:?}", h.bfs(Node::Col(0)));

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.