CSRMatrix
Module: strata.core • Kind: struct • Traits: ArrayLike, Copyable, Movable, SparseMatrix, Writable
Source: strata/core/csr_matrix.mojo
struct CSRMatrix[dtype: DType = DType.float64](ArrayLike, Copyable, Movable, SparseMatrix, Writable)from strata.core import CSRMatrixCompressed Sparse Row (CSR) 2D matrix format.
Constructors
Section titled “Constructors”def __init__( out self, rows: Int, cols: Int, var data: List[Scalar[Self.dtype]], var indices: List[Int], var indptr: List[Int],)| Argument | Type | Description |
|---|---|---|
rows |
Int |
— |
cols |
Int |
— |
Methods Overview
Section titled “Methods Overview”| Method | Description |
|---|---|
CSRMatrix.empty() |
Create an empty sparse matrix of the given dimensions. |
CSRMatrix.from_scipy() |
Construct from a scipy.sparse matrix. |
CSRMatrix.to_scipy() |
Convert to a scipy.sparse matrix. |
CSRMatrix.from_dense() |
Construct a sparse matrix from a dense Matrix. |
CSRMatrix.to_dense() |
Convert the sparse matrix to a dense Matrix. |
CSRMatrix.to_csc() |
Convert to Compressed Sparse Column (CSCMatrix) format. |
CSRMatrix.num_rows() |
Return the number of rows. |
CSRMatrix.num_cols() |
Return the number of columns. |
CSRMatrix.num_elements() |
Return the total number of elements (rows * cols). |
CSRMatrix.shape() |
Return the (rows, cols) dimensions tuple. |
CSRMatrix.cast() |
Promotes or converts the CSRMatrix data elements to target_dtype. |
CSRMatrix.nnz() |
Return the number of stored non-zero entries. |
CSRMatrix.dot_vec() |
Compute matrix-vector product. |
CSRMatrix.dot_dense() |
Compute sparse-dense matrix multiplication. |
CSRMatrix.dot_sparse() |
Compute sparse-sparse matrix multiplication. |
CSRMatrix.write_to() |
Format a human-readable string representation to a writer. |
Method Details
Section titled “Method Details”CSRMatrix.empty()
Section titled “CSRMatrix.empty()”def empty(rows: Int, cols: Int) -> SelfCreate an empty sparse matrix of the given dimensions.
| Parameter | Type | Description |
|---|---|---|
rows |
Int |
— |
cols |
Int |
— |
Returns: Self
CSRMatrix.from_scipy()
Section titled “CSRMatrix.from_scipy()”def from_scipy(sp_arr: PythonObject) -> SelfConstruct from a scipy.sparse matrix.
| Parameter | Type | Description |
|---|---|---|
sp_arr |
PythonObject |
— |
Returns: Self
CSRMatrix.to_scipy()
Section titled “CSRMatrix.to_scipy()”def to_scipy(self) -> PythonObjectConvert to a scipy.sparse matrix.
Returns: PythonObject
CSRMatrix.from_dense()
Section titled “CSRMatrix.from_dense()”def from_dense(dense: Matrix[Self.dtype]) -> SelfConstruct a sparse matrix from a dense Matrix.
| Parameter | Type | Description |
|---|---|---|
dense |
Matrix[Self.dtype] |
— |
Returns: Self
CSRMatrix.to_dense()
Section titled “CSRMatrix.to_dense()”def to_dense(self) -> Matrix[Self.dtype]Convert the sparse matrix to a dense Matrix.
Returns: Matrix[Self.dtype]
CSRMatrix.to_csc()
Section titled “CSRMatrix.to_csc()”def to_csc(self) -> CSCMatrix[Self.dtype]Convert to Compressed Sparse Column (CSCMatrix) format.
Returns: CSCMatrix[Self.dtype]
CSRMatrix.num_rows()
Section titled “CSRMatrix.num_rows()”def num_rows(self) -> IntReturn the number of rows.
Returns: Int
CSRMatrix.num_cols()
Section titled “CSRMatrix.num_cols()”def num_cols(self) -> IntReturn the number of columns.
Returns: Int
CSRMatrix.num_elements()
Section titled “CSRMatrix.num_elements()”def num_elements(self) -> IntReturn the total number of elements (rows * cols).
Returns: Int
CSRMatrix.shape()
Section titled “CSRMatrix.shape()”def shape(self) -> Tuple[Int, Int]Return the (rows, cols) dimensions tuple.
Returns: Tuple[Int, Int]
CSRMatrix.cast()
Section titled “CSRMatrix.cast()”def cast[target_dtype: DType](self) -> CSRMatrix[target_dtype]Promotes or converts the CSRMatrix data elements to target_dtype.
Returns: CSRMatrix[target_dtype]
CSRMatrix.nnz()
Section titled “CSRMatrix.nnz()”def nnz(self) -> IntReturn the number of stored non-zero entries.
Returns: Int
CSRMatrix.dot_vec()
Section titled “CSRMatrix.dot_vec()”def dot_vec(self, vec: List[Scalar[Self.dtype]]) -> List[Scalar[Self.dtype]]Compute matrix-vector product.
| Parameter | Type | Description |
|---|---|---|
vec |
List[Scalar[Self.dtype]] |
— |
Returns: List[Scalar[Self.dtype]]
CSRMatrix.dot_dense()
Section titled “CSRMatrix.dot_dense()”def dot_dense(self, other: Matrix[Self.dtype]) -> Matrix[Self.dtype]Compute sparse-dense matrix multiplication.
| Parameter | Type | Description |
|---|---|---|
other |
Matrix[Self.dtype] |
— |
Returns: Matrix[Self.dtype]
CSRMatrix.dot_sparse()
Section titled “CSRMatrix.dot_sparse()”def dot_sparse(self, other: Self) -> SelfCompute sparse-sparse matrix multiplication.
| Parameter | Type | Description |
|---|---|---|
other |
Self |
— |
Returns: Self
CSRMatrix.write_to()
Section titled “CSRMatrix.write_to()”def write_to(self, mut writer: Some[Writer])Format a human-readable string representation to a writer.