pub trait SparseArray<T>: Anywhere
T: Float + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Debug + Copy + 'static,{
Show 32 methods
// Required methods
fn shape(&self) -> (usize, usize);
fn nnz(&self) -> usize;
fn dtype(&self) -> &str;
fn to_array(&self) -> Array2<T>;
fn toarray(&self) -> Array2<T>;
fn to_coo(&self) -> SparseResult<Box<dyn SparseArray<T>>>;
fn to_csr(&self) -> SparseResult<Box<dyn SparseArray<T>>>;
fn to_csc(&self) -> SparseResult<Box<dyn SparseArray<T>>>;
fn to_dok(&self) -> SparseResult<Box<dyn SparseArray<T>>>;
fn to_lil(&self) -> SparseResult<Box<dyn SparseArray<T>>>;
fn to_dia(&self) -> SparseResult<Box<dyn SparseArray<T>>>;
fn to_bsr(&self) -> SparseResult<Box<dyn SparseArray<T>>>;
fn add(
&self,
other: &dyn SparseArray<T>,
) -> SparseResult<Box<dyn SparseArray<T>>>;
fn sub(
&self,
other: &dyn SparseArray<T>,
) -> SparseResult<Box<dyn SparseArray<T>>>;
fn mul(
&self,
other: &dyn SparseArray<T>,
) -> SparseResult<Box<dyn SparseArray<T>>>;
fn div(
&self,
other: &dyn SparseArray<T>,
) -> SparseResult<Box<dyn SparseArray<T>>>;
fn dot(
&self,
other: &dyn SparseArray<T>,
) -> SparseResult<Box<dyn SparseArray<T>>>;
fn dot_vector(&self, other: &ArrayView1<'_, T>) -> SparseResult<Array1<T>>;
fn transpose(&self) -> SparseResult<Box<dyn SparseArray<T>>>;
fn copy(&self) -> Box<dyn SparseArray<T>>;
fn get(&self, i: usize, j: usize) -> T;
fn set(&mut self, i: usize, j: usize, value: T) -> SparseResult<()>;
fn eliminate_zeros(&mut self);
fn sort_indices(&mut self);
fn sorted_indices(&self) -> Box<dyn SparseArray<T>>;
fn has_sorted_indices(&self) -> bool;
fn sum(&self, axis: Option<usize>) -> SparseResult<SparseSum<T>>;
fn max(&self) -> T;
fn min(&self) -> T;
fn find(&self) -> (Array1<usize>, Array1<usize>, Array1<T>);
fn slice(
&self,
row_range: (usize, usize),
col_range: (usize, usize),
) -> SparseResult<Box<dyn SparseArray<T>>>;
fn as_any(&self) -> &dyn Any;
}
Expand description
Trait for sparse array types.
This trait defines the common interface for all sparse array implementations. It is designed to align with SciPy’s sparse array API, providing array-like semantics rather than matrix-like semantics.
§Notes
The sparse array API differs from the sparse matrix API in the following ways:
*
operator performs element-wise multiplication, not matrix multiplication- Matrix multiplication is done with the
dot
method or@
operator in Python - Operations like
sum
produce arrays, not matrices - Sparse arrays use array-style slicing operations
Required Methods§
Sourcefn to_coo(&self) -> SparseResult<Box<dyn SparseArray<T>>>
fn to_coo(&self) -> SparseResult<Box<dyn SparseArray<T>>>
Returns a sparse array in COO format.
Sourcefn to_csr(&self) -> SparseResult<Box<dyn SparseArray<T>>>
fn to_csr(&self) -> SparseResult<Box<dyn SparseArray<T>>>
Returns a sparse array in CSR format.
Sourcefn to_csc(&self) -> SparseResult<Box<dyn SparseArray<T>>>
fn to_csc(&self) -> SparseResult<Box<dyn SparseArray<T>>>
Returns a sparse array in CSC format.
Sourcefn to_dok(&self) -> SparseResult<Box<dyn SparseArray<T>>>
fn to_dok(&self) -> SparseResult<Box<dyn SparseArray<T>>>
Returns a sparse array in DOK format.
Sourcefn to_lil(&self) -> SparseResult<Box<dyn SparseArray<T>>>
fn to_lil(&self) -> SparseResult<Box<dyn SparseArray<T>>>
Returns a sparse array in LIL format.
Sourcefn to_dia(&self) -> SparseResult<Box<dyn SparseArray<T>>>
fn to_dia(&self) -> SparseResult<Box<dyn SparseArray<T>>>
Returns a sparse array in DIA format.
Sourcefn to_bsr(&self) -> SparseResult<Box<dyn SparseArray<T>>>
fn to_bsr(&self) -> SparseResult<Box<dyn SparseArray<T>>>
Returns a sparse array in BSR format.
Sourcefn add(
&self,
other: &dyn SparseArray<T>,
) -> SparseResult<Box<dyn SparseArray<T>>>
fn add( &self, other: &dyn SparseArray<T>, ) -> SparseResult<Box<dyn SparseArray<T>>>
Element-wise addition.
Sourcefn sub(
&self,
other: &dyn SparseArray<T>,
) -> SparseResult<Box<dyn SparseArray<T>>>
fn sub( &self, other: &dyn SparseArray<T>, ) -> SparseResult<Box<dyn SparseArray<T>>>
Element-wise subtraction.
Sourcefn mul(
&self,
other: &dyn SparseArray<T>,
) -> SparseResult<Box<dyn SparseArray<T>>>
fn mul( &self, other: &dyn SparseArray<T>, ) -> SparseResult<Box<dyn SparseArray<T>>>
Element-wise multiplication.
Sourcefn div(
&self,
other: &dyn SparseArray<T>,
) -> SparseResult<Box<dyn SparseArray<T>>>
fn div( &self, other: &dyn SparseArray<T>, ) -> SparseResult<Box<dyn SparseArray<T>>>
Element-wise division.
Sourcefn dot(
&self,
other: &dyn SparseArray<T>,
) -> SparseResult<Box<dyn SparseArray<T>>>
fn dot( &self, other: &dyn SparseArray<T>, ) -> SparseResult<Box<dyn SparseArray<T>>>
Matrix multiplication.
Sourcefn dot_vector(&self, other: &ArrayView1<'_, T>) -> SparseResult<Array1<T>>
fn dot_vector(&self, other: &ArrayView1<'_, T>) -> SparseResult<Array1<T>>
Matrix-vector multiplication.
Sourcefn transpose(&self) -> SparseResult<Box<dyn SparseArray<T>>>
fn transpose(&self) -> SparseResult<Box<dyn SparseArray<T>>>
Transpose the sparse array.
Sourcefn copy(&self) -> Box<dyn SparseArray<T>>
fn copy(&self) -> Box<dyn SparseArray<T>>
Return a copy of the sparse array with the specified elements.
Sourcefn set(&mut self, i: usize, j: usize, value: T) -> SparseResult<()>
fn set(&mut self, i: usize, j: usize, value: T) -> SparseResult<()>
Set a value at the specified position.
Sourcefn eliminate_zeros(&mut self)
fn eliminate_zeros(&mut self)
Eliminate zeros from the sparse array.
Sourcefn sort_indices(&mut self)
fn sort_indices(&mut self)
Sort indices of the sparse array.
Sourcefn sorted_indices(&self) -> Box<dyn SparseArray<T>>
fn sorted_indices(&self) -> Box<dyn SparseArray<T>>
Return a sorted copy of this sparse array.
Sourcefn has_sorted_indices(&self) -> bool
fn has_sorted_indices(&self) -> bool
Check if indices are sorted.
Sourcefn sum(&self, axis: Option<usize>) -> SparseResult<SparseSum<T>>
fn sum(&self, axis: Option<usize>) -> SparseResult<SparseSum<T>>
Sum the sparse array elements.
Parameters:
axis
: The axis along which to sum. If None, sum over both axes.
Returns a sparse array if summing over a single axis, or a scalar if summing over both axes.
Sourcefn find(&self) -> (Array1<usize>, Array1<usize>, Array1<T>)
fn find(&self) -> (Array1<usize>, Array1<usize>, Array1<T>)
Return the indices and values of the nonzero elements.
Sourcefn slice(
&self,
row_range: (usize, usize),
col_range: (usize, usize),
) -> SparseResult<Box<dyn SparseArray<T>>>
fn slice( &self, row_range: (usize, usize), col_range: (usize, usize), ) -> SparseResult<Box<dyn SparseArray<T>>>
Return a slice of the sparse array.
Implementors§
impl<T> SparseArray<T> for BsrArray<T>
impl<T> SparseArray<T> for CooArray<T>
impl<T> SparseArray<T> for CscArray<T>
impl<T> SparseArray<T> for CsrArray<T>
impl<T> SparseArray<T> for DiaArray<T>
impl<T> SparseArray<T> for DokArray<T>
impl<T> SparseArray<T> for LilArray<T>
impl<T> SparseArray<T> for SymCooArray<T>
Implementation of SparseArray for SymCooArray
impl<T> SparseArray<T> for SymCsrArray<T>
Implementation of SparseArray for SymCsrArray