pub struct CooMatrix<T: Scalar> { /* private fields */ }Expand description
Sparse matrix in COO (coordinate / triplet) format.
Stores (row, col, value) triplets. Duplicate entries are summed during conversion to CSR/CSC.
§Examples
let mut coo = CooMatrix::<f64>::new(3, 3);
coo.push(0, 0, 1.0).unwrap();
coo.push(1, 1, 2.0).unwrap();
assert_eq!(coo.nnz(), 2);Implementations§
Source§impl<T: Scalar> CooMatrix<T>
impl<T: Scalar> CooMatrix<T>
Sourcepub fn new(nrows: usize, ncols: usize) -> Self
pub fn new(nrows: usize, ncols: usize) -> Self
Create an empty COO matrix with the given dimensions.
§Examples
let coo = CooMatrix::<f64>::new(3, 3);
assert_eq!(coo.nnz(), 0);
assert_eq!(coo.shape(), (3, 3));Sourcepub fn from_triplets(
nrows: usize,
ncols: usize,
rows: Vec<usize>,
cols: Vec<usize>,
values: Vec<T>,
) -> Result<Self>
pub fn from_triplets( nrows: usize, ncols: usize, rows: Vec<usize>, cols: Vec<usize>, values: Vec<T>, ) -> Result<Self>
Build a COO matrix from triplet arrays.
§Examples
let coo = CooMatrix::from_triplets(
2, 2,
vec![0, 1], vec![0, 1], vec![1.0, 2.0],
).unwrap();
assert_eq!(coo.nnz(), 2);Sourcepub fn push(&mut self, row: usize, col: usize, value: T) -> Result<()>
pub fn push(&mut self, row: usize, col: usize, value: T) -> Result<()>
Append a single entry.
§Examples
let mut coo = CooMatrix::<f64>::new(2, 2);
coo.push(0, 1, 3.5).unwrap();
assert_eq!(coo.nnz(), 1);Sourcepub fn to_dense(&self) -> Tensor<T>
pub fn to_dense(&self) -> Tensor<T>
Convert to a dense 2-D tensor. Duplicate entries are summed.
§Examples
let coo = CooMatrix::from_triplets(
2, 2,
vec![0, 1], vec![0, 1], vec![1.0, 2.0],
).unwrap();
let dense = coo.to_dense();
assert_eq!(dense.shape(), &[2, 2]);
assert_eq!(dense.as_slice(), &[1.0, 0.0, 0.0, 2.0]);Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for CooMatrix<T>
impl<T> RefUnwindSafe for CooMatrix<T>where
T: RefUnwindSafe,
impl<T> Send for CooMatrix<T>
impl<T> Sync for CooMatrix<T>
impl<T> Unpin for CooMatrix<T>where
T: Unpin,
impl<T> UnsafeUnpin for CooMatrix<T>
impl<T> UnwindSafe for CooMatrix<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more