Struct nalgebra_sparse::coo::CooMatrix[][src]

pub struct CooMatrix<T> { /* fields omitted */ }

A COO representation of a sparse matrix.

A COO matrix stores entries in coordinate-form, that is triplets (i, j, v), where i and j correspond to row and column indices of the entry, and v to the value of the entry. The format is of limited use for standard matrix operations. Its main purpose is to facilitate easy construction of other, more efficient matrix formats (such as CSR/COO), and the conversion between different formats.

Format

For given dimensions nrows and ncols, the matrix is represented by three same-length arrays row_indices, col_indices and values that constitute the coordinate triplets of the matrix. The indices must be in bounds, but duplicate entries are explicitly allowed. Upon conversion to other formats, the duplicate entries may be summed together. See the documentation for the respective conversion functions.

Examples

use nalgebra_sparse::{coo::CooMatrix, csr::CsrMatrix, csc::CscMatrix};

// Initialize a matrix with all zeros (no explicitly stored entries).
let mut coo = CooMatrix::new(4, 4);
// Or initialize it with a set of triplets
coo = CooMatrix::try_from_triplets(4, 4, vec![1, 2], vec![0, 1], vec![3.0, 4.0]).unwrap();

// Push a few triplets
coo.push(2, 0, 1.0);
coo.push(0, 1, 2.0);

// Convert to other matrix formats
let csr = CsrMatrix::from(&coo);
let csc = CscMatrix::from(&coo);

Implementations

impl<T> CooMatrix<T>[src]

pub fn new(nrows: usize, ncols: usize) -> Self[src]

Construct a zero COO matrix of the given dimensions.

Specifically, the collection of triplets - corresponding to explicitly stored entries - is empty, so that the matrix (implicitly) represented by the COO matrix consists of all zero entries.

pub fn zeros(nrows: usize, ncols: usize) -> Self[src]

Construct a zero COO matrix of the given dimensions.

Specifically, the collection of triplets - corresponding to explicitly stored entries - is empty, so that the matrix (implicitly) represented by the COO matrix consists of all zero entries.

pub fn try_from_triplets(
    nrows: usize,
    ncols: usize,
    row_indices: Vec<usize>,
    col_indices: Vec<usize>,
    values: Vec<T>
) -> Result<Self, SparseFormatError>
[src]

Try to construct a COO matrix from the given dimensions and a collection of (i, j, v) triplets.

Returns an error if either row or column indices contain indices out of bounds, or if the data arrays do not all have the same length. Note that the COO format inherently supports duplicate entries.

pub fn triplet_iter(&self) -> impl Iterator<Item = (usize, usize, &T)>[src]

An iterator over triplets (i, j, v).

pub fn push(&mut self, i: usize, j: usize, v: T)[src]

Push a single triplet to the matrix.

This adds the value v to the ith row and jth column in the matrix.

Panics

Panics if i or j is out of bounds.

pub fn nrows(&self) -> usize[src]

The number of rows in the matrix.

pub fn ncols(&self) -> usize[src]

The number of columns in the matrix.

pub fn nnz(&self) -> usize[src]

The number of explicitly stored entries in the matrix.

This number includes duplicate entries. For example, if the CooMatrix contains duplicate entries, then it may have a different number of non-zeros as reported by nnz() compared to its CSR representation.

pub fn row_indices(&self) -> &[usize][src]

The row indices of the explicitly stored entries.

pub fn col_indices(&self) -> &[usize][src]

The column indices of the explicitly stored entries.

pub fn values(&self) -> &[T][src]

The values of the explicitly stored entries.

pub fn disassemble(self) -> (Vec<usize>, Vec<usize>, Vec<T>)[src]

Disassembles the matrix into individual triplet arrays.

Examples

let row_indices = vec![0, 1];
let col_indices = vec![1, 2];
let values = vec![1.0, 2.0];
let coo = CooMatrix::try_from_triplets(2, 3, row_indices, col_indices, values)
    .unwrap();

let (row_idx, col_idx, val) = coo.disassemble();
assert_eq!(row_idx, vec![0, 1]);
assert_eq!(col_idx, vec![1, 2]);
assert_eq!(val, vec![1.0, 2.0]);

Trait Implementations

impl<T: Clone> Clone for CooMatrix<T>[src]

impl<T: Debug> Debug for CooMatrix<T>[src]

impl<T: Eq> Eq for CooMatrix<T>[src]

impl<'a, T> From<&'a CooMatrix<T>> for CsrMatrix<T> where
    T: Scalar + Zero + ClosedAdd, 
[src]

impl<'a, T> From<&'a CooMatrix<T>> for CscMatrix<T> where
    T: Scalar + Zero + ClosedAdd, 
[src]

impl<'a, T> From<&'a CscMatrix<T>> for CooMatrix<T> where
    T: Scalar + Zero
[src]

impl<'a, T> From<&'a CsrMatrix<T>> for CooMatrix<T> where
    T: Scalar + Zero + ClosedAdd, 
[src]

impl<'a, T, R, C, S> From<&'a Matrix<T, R, C, S>> for CooMatrix<T> where
    T: Scalar + Zero,
    R: Dim,
    C: Dim,
    S: Storage<T, R, C>, 
[src]

impl<T: Clone> Matrix<T> for CooMatrix<T>[src]

impl<T: PartialEq> PartialEq<CooMatrix<T>> for CooMatrix<T>[src]

impl<T: Clone> SparseAccess<T> for CooMatrix<T>[src]

impl<T> StructuralEq for CooMatrix<T>[src]

impl<T> StructuralPartialEq for CooMatrix<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for CooMatrix<T> where
    T: RefUnwindSafe

impl<T> Send for CooMatrix<T> where
    T: Send

impl<T> Sync for CooMatrix<T> where
    T: Sync

impl<T> Unpin for CooMatrix<T> where
    T: Unpin

impl<T> UnwindSafe for CooMatrix<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,