pub type CsMatI<N, I, Iptr = I> = CsMatBase<N, I, Vec<Iptr>, Vec<I>, Vec<N>, Iptr>;Aliased Type§
pub struct CsMatI<N, I, Iptr = I> { /* private fields */ }Implementations§
Source§impl<N, I: SpIndex, Iptr: SpIndex> CsMatI<N, I, Iptr>
§Constructor methods for owned sparse matrices
impl<N, I: SpIndex, Iptr: SpIndex> CsMatI<N, I, Iptr>
§Constructor methods for owned sparse matrices
Sourcepub fn eye(dim: usize) -> Self
pub fn eye(dim: usize) -> Self
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);Sourcepub fn eye_csc(dim: usize) -> Self
pub fn eye_csc(dim: usize) -> Self
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);Sourcepub fn empty(storage: CompressedStorage, inner_size: usize) -> Self
pub fn empty(storage: CompressedStorage, inner_size: usize) -> Self
Create an empty CsMat for building purposes
Sourcepub fn zero(shape: Shape) -> Self
pub fn zero(shape: Shape) -> Self
Create a new CsMat representing the zero matrix.
Hence it has no non-zero elements.
Sourcepub fn reserve_outer_dim(&mut self, outer_dim_additional: usize)
pub fn reserve_outer_dim(&mut self, outer_dim_additional: usize)
Reserve the storage for the given additional number of nonzero data
Sourcepub fn reserve_nnz(&mut self, nnz_additional: usize)
pub fn reserve_nnz(&mut self, nnz_additional: usize)
Reserve the storage for the given additional number of nonzero data
Sourcepub fn reserve_outer_dim_exact(&mut self, outer_dim_lim: usize)
pub fn reserve_outer_dim_exact(&mut self, outer_dim_lim: usize)
Reserve the storage for the given number of nonzero data
Sourcepub fn reserve_nnz_exact(&mut self, nnz_lim: usize)
pub fn reserve_nnz_exact(&mut self, nnz_lim: usize)
Reserve the storage for the given number of nonzero data
Sourcepub fn csr_from_dense(m: ArrayView<'_, N, Ix2>, epsilon: N) -> Self
pub fn csr_from_dense(m: ArrayView<'_, N, Ix2>, epsilon: N) -> Self
Create a CSR matrix from a dense matrix, ignoring elements lower than epsilon.
If epsilon is negative, it will be clamped to zero.
Sourcepub fn csc_from_dense(m: ArrayView<'_, N, Ix2>, epsilon: N) -> Self
pub fn csc_from_dense(m: ArrayView<'_, N, Ix2>, epsilon: N) -> Self
Create a CSC matrix from a dense matrix, ignoring elements lower than epsilon.
If epsilon is negative, it will be clamped to zero.
Sourcepub fn append_outer(self, data: &[N]) -> Self
pub fn append_outer(self, data: &[N]) -> Self
Append an outer dim to an existing matrix, compressing it in the process
Sourcepub fn append_outer_iter<Iter>(self, iter: Iter) -> Self
pub fn append_outer_iter<Iter>(self, iter: Iter) -> Self
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
Sourcepub unsafe fn append_outer_iter_unchecked<Iter>(self, iter: Iter) -> Selfwhere
Iter: IntoIterator<Item = (usize, N)>,
pub unsafe fn append_outer_iter_unchecked<Iter>(self, iter: Iter) -> Selfwhere
Iter: IntoIterator<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
Sourcepub fn append_outer_csvec(self, vec: CsVecViewI<'_, N, I>) -> Selfwhere
N: Clone,
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
Sourcepub fn insert(&mut self, row: usize, col: usize, val: N)
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.