Struct sprs::CsMat [] [src]

pub struct CsMat<N, IptrStorage, IndStorage, DataStorage> where IptrStorage: Deref<Target=[usize]>, IndStorage: Deref<Target=[usize]>, DataStorage: Deref<Target=[N]> {
    // some fields omitted
}

Compressed matrix in the CSR or CSC format.

Methods

impl<N, IptrStorage, IndStorage, DataStorage> CsMat<N, IptrStorage, IndStorage, DataStorage> where N: Copy, IptrStorage: Deref<Target=[usize]>, IndStorage: Deref<Target=[usize]>, DataStorage: Deref<Target=[N]>
[src]

fn outer_iterator<'a>(&'a self) -> OuterIterator<'a, N>

Return an outer iterator for the matrix

This can be used for iterating over the rows (resp. cols) of a CSR (resp. CSC) matrix.

use sprs::{CsMat};
let eye = CsMat::eye(sprs::CSR, 5);
for (row_ind, row_vec) in eye.outer_iterator() {
    let (col_ind, val): (_, f64) = row_vec.iter().next().unwrap();
    assert_eq!(row_ind, col_ind);
    assert_eq!(val, 1.);
}

fn outer_iterator_perm<'a, 'perm: 'a>(&'a self, perm: &'perm Permutation<&'perm [usize]>) -> OuterIteratorPerm<'a, 'perm, N>

Return an outer iterator over P*A, as well as the proper permutation for iterating over the inner dimension of P*A*PT Unstable

fn storage(&self) -> CompressedStorage

The underlying storage of this matrix

fn rows(&self) -> usize

The number of rows of this matrix

fn cols(&self) -> usize

The number of cols of this matrix

fn nb_nonzero(&self) -> usize

The number of non-zero elements this matrix stores. This is often relevant for the complexity of most sparse matrix algorithms, which are often linear in the number of non-zeros.

fn outer_dims(&self) -> usize

Number of outer dimensions, that ie equal to self.rows() for a CSR matrix, and equal to self.cols() for a CSC matrix

fn inner_dims(&self) -> usize

Number of inner dimensions, that ie equal to self.cols() for a CSR matrix, and equal to self.rows() for a CSC matrix

fn at(&self, (i, j): &(usize, usize)) -> Option<N>

Access the element located at row i and column j. Will return None if there is no non-zero element at this location.

This access is logarithmic in the number of non-zeros in the corresponding outer slice. It is therefore advisable not to rely on this for algorithms, and prefer outer_iterator() which accesses elements in storage order.

fn outer_view(&self, i: usize) -> Option<CsVecView<N>>

Get a view into the i-th outer dimension (eg i-th row for a CSR matrix)

fn indptr(&self) -> &[usize]

The array of offsets in the indices() and data() slices. The elements of the slice at outer dimension i are available between the elements indptr[i] and indptr[i+1] in the indices() and data() slices.

Example

use sprs::{CsMat, CsMatOwned};
let eye : CsMatOwned<f64> = CsMat::eye(sprs::CSR, 5);
// get the element of row 3
// there is only one element in this row, with a column index of 3
// and a value of 1.
let loc = eye.indptr()[3];
assert_eq!(eye.indptr()[4], loc + 1);
assert_eq!(loc, 3);
assert_eq!(eye.indices()[loc], 3);
assert_eq!(eye.data()[loc], 1.);

fn indices(&self) -> &[usize]

The inner dimension location for each non-zero value. See the documentation of indptr() for more explanations.

fn data(&self) -> &[N]

The non-zero values. See the documentation of indptr() for more explanations.

fn is_csc(&self) -> bool

Test whether the matrix is in CSC storage

fn is_csr(&self) -> bool

Test whether the matrix is in CSR storage

fn transpose_mut(&mut self)

Transpose a matrix in place No allocation required (this is simply a storage order change)

fn transpose_into(self) -> Self

Transpose a matrix in place No allocation required (this is simply a storage order change)

fn transpose_view(&self) -> CsMatView<N>

Transposed view of this matrix No allocation required (this is simply a storage order change)

fn to_owned(&self) -> CsMatOwned<N>

Get an owned version of this matrix. If the matrix was already owned, this will make a deep copy.

fn at_outer_inner(&self, (outer_ind, inner_ind): &(usize, usize)) -> Option<N>

Access an element given its outer_ind and inner_ind. Will return None if there is no non-zero element at this location.

This access is logarithmic in the number of non-zeros in the corresponding outer slice. It is therefore advisable not to rely on this for algorithms, and prefer outer_iterator() which accesses elements in storage order.

fn check_compressed_structure(&self) -> Result<()SprsError>

Check the structure of CsMat components This will ensure that: - indptr is of length outer_dim() + 1 - indices and data have the same length, nnz == indptr[outer_dims()] - indptr is sorted - indices is sorted for each outer slice - indices are lower than inner_dims()

fn borrowed(&self) -> CsMatView<N>

Return a view into the current matrix

impl<N, IptrStorage, IndStorage, DataStorage> CsMat<N, IptrStorage, IndStorage, DataStorage> where N: Copy + Default, IptrStorage: Deref<Target=[usize]>, IndStorage: Deref<Target=[usize]>, DataStorage: Deref<Target=[N]>
[src]

fn to_other_storage(&self) -> CsMatOwned<N>

Create a matrix mathematically equal to this one, but with the opposed storage (a CSC matrix will be converted to CSR, and vice versa)

fn to_csc(&self) -> CsMatOwned<N>

Create a new CSC matrix equivalent to this one. A new matrix will be created even if this matrix was already CSC.

fn to_csr(&self) -> CsMatOwned<N>

Create a new CSR matrix equivalent to this one. A new matrix will be created even if this matrix was already CSR.

impl<N, IptrStorage, IndStorage, DataStorage> CsMat<N, IptrStorage, IndStorage, DataStorage> where N: Copy, IptrStorage: DerefMut<Target=[usize]>, IndStorage: DerefMut<Target=[usize]>, DataStorage: DerefMut<Target=[N]>
[src]

fn data_mut(&mut self) -> &mut [N]

Mutable access to the non zero values

fn scale(&mut self, val: N) where N: Num + Copy

Sparse matrix self-multiplication by a scalar

Trait Implementations

impl<N: Debug, IptrStorage: Debug, IndStorage: Debug, DataStorage: Debug> Debug for CsMat<N, IptrStorage, IndStorage, DataStorage> where IptrStorage: Deref<Target=[usize]>, IndStorage: Deref<Target=[usize]>, DataStorage: Deref<Target=[N]>
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

impl<N: PartialEq, IptrStorage: PartialEq, IndStorage: PartialEq, DataStorage: PartialEq> PartialEq for CsMat<N, IptrStorage, IndStorage, DataStorage> where IptrStorage: Deref<Target=[usize]>, IndStorage: Deref<Target=[usize]>, DataStorage: Deref<Target=[N]>
[src]

fn eq(&self, __arg_0: &CsMat<N, IptrStorage, IndStorage, DataStorage>) -> bool

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

fn ne(&self, __arg_0: &CsMat<N, IptrStorage, IndStorage, DataStorage>) -> bool

This method tests for !=.

impl<'a, 'b, N, IpStorage, IStorage, DStorage, Mat> Add<&'b Mat> for &'a CsMat<N, IpStorage, IStorage, DStorage> where N: 'a + Copy + Num + Default, IpStorage: 'a + Deref<Target=[usize]>, IStorage: 'a + Deref<Target=[usize]>, DStorage: 'a + Deref<Target=[N]>, Mat: SpMatView<N>
[src]

type Output = CsMatOwned<N>

The resulting type after applying the + operator

fn add(self, rhs: &'b Mat) -> CsMatOwned<N>

The method for the + operator

impl<'a, 'b, N, IpStorage, IStorage, DStorage, Mat> Sub<&'b Mat> for &'a CsMat<N, IpStorage, IStorage, DStorage> where N: 'a + Copy + Num + Default, IpStorage: 'a + Deref<Target=[usize]>, IStorage: 'a + Deref<Target=[usize]>, DStorage: 'a + Deref<Target=[N]>, Mat: SpMatView<N>
[src]

type Output = CsMatOwned<N>

The resulting type after applying the - operator

fn sub(self, rhs: &'b Mat) -> CsMatOwned<N>

The method for the - operator

impl<'a, N, IpStorage, IStorage, DStorage> Mul<N> for &'a CsMat<N, IpStorage, IStorage, DStorage> where N: 'a + Copy + Num, IpStorage: 'a + Deref<Target=[usize]>, IStorage: 'a + Deref<Target=[usize]>, DStorage: 'a + Deref<Target=[N]>
[src]

type Output = CsMatOwned<N>

The resulting type after applying the * operator

fn mul(self, rhs: N) -> CsMatOwned<N>

The method for the * operator

impl<'a, 'b, N, IpS1, IS1, DS1, IpS2, IS2, DS2> Mul<&'b CsMat<N, IpS2, IS2, DS2>> for &'a CsMat<N, IpS1, IS1, DS1> where N: 'a + Copy + Num + Default, IpS1: 'a + Deref<Target=[usize]>, IS1: 'a + Deref<Target=[usize]>, DS1: 'a + Deref<Target=[N]>, IpS2: 'b + Deref<Target=[usize]>, IS2: 'b + Deref<Target=[usize]>, DS2: 'b + Deref<Target=[N]>
[src]

type Output = CsMatOwned<N>

The resulting type after applying the * operator

fn mul(self, rhs: &'b CsMat<N, IpS2, IS2, DS2>) -> CsMatOwned<N>

The method for the * operator

impl<'a, 'b, N, IpS1, IS1, DS1, IS2, DS2> Mul<&'b CsVec<N, IS2, DS2>> for &'a CsMat<N, IpS1, IS1, DS1> where N: Copy + Num + Default, IpS1: Deref<Target=[usize]>, IS1: Deref<Target=[usize]>, DS1: Deref<Target=[N]>, IS2: Deref<Target=[usize]>, DS2: Deref<Target=[N]>
[src]

type Output = CsVecOwned<N>

The resulting type after applying the * operator

fn mul(self, rhs: &CsVec<N, IS2, DS2>) -> CsVecOwned<N>

The method for the * operator

impl<N, IpStorage, IndStorage, DataStorage> SpMatView<N> for CsMat<N, IpStorage, IndStorage, DataStorage> where N: Copy, IpStorage: Deref<Target=[usize]>, IndStorage: Deref<Target=[usize]>, DataStorage: Deref<Target=[N]>
[src]

fn borrowed(&self) -> CsMatView<N>

Return a view into the current matrix

fn transpose_view(&self) -> CsMatView<N>

Return a view into the current matrix