pub struct CooMatrix<T> { /* private fields */ }
Expand description
Coordinate (COO) matrix
A sparse matrix format that stores triplets (row, column, value), making it efficient for construction and modification.
Implementations§
Source§impl<T> CooMatrix<T>
impl<T> CooMatrix<T>
Sourcepub fn get_triplets(&self) -> (Vec<usize>, Vec<usize>, Vec<T>)
pub fn get_triplets(&self) -> (Vec<usize>, Vec<usize>, Vec<T>)
Get the triplets (row indices, column indices, data)
Sourcepub fn new(
data: Vec<T>,
row_indices: Vec<usize>,
col_indices: Vec<usize>,
shape: (usize, usize),
) -> SparseResult<Self>
pub fn new( data: Vec<T>, row_indices: Vec<usize>, col_indices: Vec<usize>, shape: (usize, usize), ) -> SparseResult<Self>
Create a new COO matrix from raw data
§Arguments
data
- Vector of non-zero valuesrow_indices
- Vector of row indices for each non-zero valuecol_indices
- Vector of column indices for each non-zero valueshape
- Tuple containing the matrix dimensions (rows, cols)
§Returns
- A new COO matrix
§Examples
use scirs2_sparse::coo::CooMatrix;
// Create a 3x3 sparse matrix with 5 non-zero elements
let rows = vec![0, 0, 1, 2, 2];
let cols = vec![0, 2, 2, 0, 1];
let data = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let shape = (3, 3);
let matrix = CooMatrix::new(data, rows, cols, shape).unwrap();
Sourcepub fn add_element(
&mut self,
row: usize,
col: usize,
value: T,
) -> SparseResult<()>
pub fn add_element( &mut self, row: usize, col: usize, value: T, ) -> SparseResult<()>
Sourcepub fn row_indices(&self) -> &[usize]
pub fn row_indices(&self) -> &[usize]
Get the row indices array
Sourcepub fn col_indices(&self) -> &[usize]
pub fn col_indices(&self) -> &[usize]
Get the column indices array
Sourcepub fn sort_by_row_col(&mut self)
pub fn sort_by_row_col(&mut self)
Sort the matrix elements by row, then column
Sourcepub fn sort_by_col_row(&mut self)
pub fn sort_by_col_row(&mut self)
Sort the matrix elements by column, then row
Sourcepub fn get(&self, row: usize, col: usize) -> Twhere
T: Zero,
pub fn get(&self, row: usize, col: usize) -> Twhere
T: Zero,
Get the value at the specified position
Sourcepub fn sum_duplicates(&mut self)where
T: Add<Output = T>,
pub fn sum_duplicates(&mut self)where
T: Add<Output = T>,
Sum duplicate entries (elements with the same row and column indices)
Auto Trait Implementations§
impl<T> Freeze for CooMatrix<T>
impl<T> RefUnwindSafe for CooMatrix<T>where
T: RefUnwindSafe,
impl<T> Send for CooMatrix<T>where
T: Send,
impl<T> Sync for CooMatrix<T>where
T: Sync,
impl<T> Unpin for CooMatrix<T>where
T: Unpin,
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more