Type Definition sprs::CsMatI

source ·
pub type CsMatI<N, I, Iptr = I> = CsMatBase<N, I, Vec<Iptr>, Vec<I>, Vec<N>, Iptr>;

Implementations§

source§

impl<N, I: SpIndex, Iptr: SpIndex> CsMatI<N, I, Iptr>

source

pub fn eye(dim: usize) -> Selfwhere N: Num + Clone,

Identity matrix, stored as a CSR matrix.

use sprs::{CsMat, CsVec};
let eye = CsMat::eye(5);
assert!(eye.is_csr());
let x = CsVec::new(5, vec![0, 2, 4], vec![1., 2., 3.]);
let y = &eye * &x;
assert_eq!(x, y);
source

pub fn eye_csc(dim: usize) -> Selfwhere N: Num + Clone,

Identity matrix, stored as a CSC matrix.

use sprs::{CsMat, CsVec};
let eye = CsMat::eye_csc(5);
assert!(eye.is_csc());
let x = CsVec::new(5, vec![0, 2, 4], vec![1., 2., 3.]);
let y = &eye * &x;
assert_eq!(x, y);
source

pub fn empty(storage: CompressedStorage, inner_size: usize) -> Self

Create an empty CsMat for building purposes

source

pub fn zero(shape: Shape) -> Self

Create a new CsMat representing the zero matrix. Hence it has no non-zero elements.

source

pub fn reserve_outer_dim(&mut self, outer_dim_additional: usize)

Reserve the storage for the given additional number of nonzero data

source

pub fn reserve_nnz(&mut self, nnz_additional: usize)

Reserve the storage for the given additional number of nonzero data

source

pub fn reserve_outer_dim_exact(&mut self, outer_dim_lim: usize)

Reserve the storage for the given number of nonzero data

source

pub fn reserve_nnz_exact(&mut self, nnz_lim: usize)

Reserve the storage for the given number of nonzero data

source

pub fn csr_from_dense(m: ArrayView<'_, N, Ix2>, epsilon: N) -> Selfwhere N: Num + Clone + PartialOrd + Signed,

Create a CSR matrix from a dense matrix, ignoring elements lower than epsilon.

If epsilon is negative, it will be clamped to zero.

source

pub fn csc_from_dense(m: ArrayView<'_, N, Ix2>, epsilon: N) -> Selfwhere N: Num + Clone + PartialOrd + Signed,

Create a CSC matrix from a dense matrix, ignoring elements lower than epsilon.

If epsilon is negative, it will be clamped to zero.

source

pub fn append_outer(self, data: &[N]) -> Selfwhere N: Clone + Zero,

Append an outer dim to an existing matrix, compressing it in the process

source

pub fn append_outer_iter<Iter>(self, iter: Iter) -> Selfwhere N: Zero, Iter: Iterator<Item = (usize, N)>,

Append an outer dim to an existing matrix, increasing the size along the outer dimension by one.

Panics

if the iterator index is not monotonically increasing

source

pub unsafe fn append_outer_iter_unchecked<Iter>(self, iter: Iter) -> Selfwhere Iter: Iterator<Item = (usize, N)>,

Append an outer dim to an existing matrix, increasing the size along the outer dimension by one.

Safety

This is unsafe since indices for each inner dim should be monotonically increasing which is not checked. The data values are additionally not checked for zero. See append_outer_iter for the checked version

source

pub fn append_outer_csvec(self, vec: CsVecViewI<'_, N, I>) -> Selfwhere N: Clone,

Append an outer dim to an existing matrix, provided by a sparse vector

source

pub fn insert(&mut self, row: usize, col: usize, val: N)

Insert an element in the matrix. If the element is already present, its value is overwritten.

Warning: this is not an efficient operation, as it requires a non-constant lookup followed by two Vec insertions.

The insertion will be efficient, however, if the elements are inserted according to the matrix’s order, eg following the row order for a CSR matrix.

source§

impl<N, I, Iptr> CsMatI<N, I, Iptr>where N: Default, I: SpIndex, Iptr: SpIndex,

source

pub fn into_csc(self) -> Selfwhere N: Clone,

Create a new CSC matrix equivalent to this one. If this matrix is CSR, it is converted to CSC If this matrix is CSC, it is returned by value

source

pub fn into_csr(self) -> Selfwhere N: Clone,

Create a new CSR matrix equivalent to this one. If this matrix is CSC, it is converted to CSR If this matrix is CSR, it is returned by value