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>
impl<N, I: SpIndex, Iptr: SpIndex> CsMatI<N, I, Iptr>
sourcepub fn eye(dim: usize) -> Selfwhere
N: Num + Clone,
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);
sourcepub fn eye_csc(dim: usize) -> Selfwhere
N: Num + Clone,
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);
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) -> Selfwhere
N: Num + Clone + PartialOrd + Signed,
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.
sourcepub fn csc_from_dense(m: ArrayView<'_, N, Ix2>, epsilon: N) -> Selfwhere
N: Num + Clone + PartialOrd + Signed,
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.
sourcepub fn append_outer(self, data: &[N]) -> Selfwhere
N: Clone + Zero,
pub fn append_outer(self, data: &[N]) -> Selfwhere N: Clone + Zero,
Append an outer dim to an existing matrix, compressing it in the process
sourcepub fn append_outer_iter<Iter>(self, iter: Iter) -> Selfwhere
N: Zero,
Iter: Iterator<Item = (usize, N)>,
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
sourcepub unsafe fn append_outer_iter_unchecked<Iter>(self, iter: Iter) -> Selfwhere
Iter: Iterator<Item = (usize, N)>,
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
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.