Module rustlearn::array::sparse [] [src]

Sparse matrices.

Two main sparse matrices are implemented: SparseRowArray and SparseColumnArray. Both support efficient incremental construction as well as efficient iteration over nonzero entries. Data is stored as indices and data vectors, in a row-wise or column-wise fashion.

SparseRowArray allows efficient iteration over rows, and SparseColumnArray allows efficient iteration over columns.

Examples

Creating and populating an array

use rustlearn::prelude::*;

let mut array = SparseRowArray::zeros(20, 5);

array.set(0, 2, 5.0);

println!("Entry at ({}, {}) is {}", 0, 2, array.get(0, 2));

Iterating over an array

use rustlearn::prelude::*;

let array = SparseRowArray::from(&Array::from(&vec![vec![1.0, 2.0],
                                                    vec![3.0, 4.0]]));

for (row_idx, row) in array.iter_rows().enumerate() {
    for (column_idx, value) in row.iter_nonzero() {
        println!("Entry at ({}, {}) is {}", row_idx, column_idx, value);
    }
}

Structs

SparseArrayIterator

Iterator over row or column views of a sparse matrix.

SparseArrayView

A view into a row or a column of an existing sparse matrix.

SparseArrayViewIterator

Iterator over nonzero entries of a SparseArrayView.

SparseColumnArray

A sparse matrix with entries arranged column-wise.

SparseRowArray

A sparse matrix with entries arranged row-wise.