Struct sprs::sparse::csmat::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<'a, N: 'a + Copy> CsMat<N, Vec<usize>, &'a [usize], &'a [N]>
[src]
unsafe fn new_vecview_raw(storage: CompressedStorage, nrows: usize, ncols: usize, indptr: Vec<usize>, indices: *const usize, data: *const N) -> CsMatVecView<'a, N>
Create a borrowed row or column CsMat matrix from raw data, without checking their validity
This is unsafe because algorithms are free to assume that properties guaranteed by check_compressed_structure are enforced. For instance, non out-of-bounds indices can be relied upon to perform unchecked slice access.
impl<'a, N: 'a + Copy> CsMat<N, &'a [usize], &'a [usize], &'a [N]>
[src]
fn new_borrowed(storage: CompressedStorage, nrows: usize, ncols: usize, indptr: &'a [usize], indices: &'a [usize], data: &'a [N]) -> Result<CsMatView<'a, N>, SprsError>
Create a borrowed CsMat matrix from sliced data, checking their validity
unsafe fn new_raw(storage: CompressedStorage, nrows: usize, ncols: usize, indptr: *const usize, indices: *const usize, data: *const N) -> CsMatView<'a, N>
Create a borrowed CsMat matrix from raw data, without checking their validity
This is unsafe because algorithms are free to assume that properties guaranteed by check_compressed_structure are enforced. For instance, non out-of-bounds indices can be relied upon to perform unchecked slice access.
impl<N: Copy> CsMat<N, Vec<usize>, Vec<usize>, Vec<N>>
[src]
fn empty(storage: CompressedStorage, inner_size: usize) -> CsMatOwned<N>
Create an empty CsMat for building purposes
fn zero(rows: usize, cols: usize) -> CsMatOwned<N>
Create a new CsMat representing the zero matrix. Hence it has no non-zero elements.
fn reserve_outer_dim(&mut self, outer_dim_additional: usize)
Reserve the storage for the given additional number of nonzero data
fn reserve_nnz(&mut self, nnz_additional: usize)
Reserve the storage for the given additional number of nonzero data
fn reserve_outer_dim_exact(&mut self, outer_dim_lim: usize)
Reserve the storage for the given number of nonzero data
fn reserve_nnz_exact(&mut self, nnz_lim: usize)
Reserve the storage for the given number of nonzero data
fn new_owned(storage: CompressedStorage, nrows: usize, ncols: usize, indptr: Vec<usize>, indices: Vec<usize>, data: Vec<N>) -> Result<CsMatOwned<N>, SprsError>
Create an owned CsMat matrix from moved data, checking their validity
fn append_outer(self, data: &[N]) -> Self where N: Num
Append an outer dim to an existing matrix, compressing it in the process
fn append_outer_csvec(self, vec: CsVec<N, &[usize], &[N]>) -> Self
Append an outer dim to an existing matrix, provided by a sparse vector
impl<N: Num + Copy> CsMat<N, Vec<usize>, Vec<usize>, Vec<N>>
[src]
fn eye(storage: CompressedStorage, dim: usize) -> CsMatOwned<N>
Identity matrix
use sprs::{CsMat, CsVec}; let eye = CsMat::eye(sprs::CSR, 5); let x = CsVec::new_owned(5, vec![0, 2, 4], vec![1., 2., 3.]).unwrap(); let y = &eye * &x; assert_eq!(x, y);
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]
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