CSCMatrix
Module: strata.core • Kind: struct • Traits: ArrayLike, Copyable, Movable, SparseMatrix, Writable
Source: strata/core/csc_matrix.mojo
struct CSCMatrix[dtype: DType = DType.float64](ArrayLike, Copyable, Movable, SparseMatrix, Writable)from strata.core import CSCMatrixCompressed Sparse Column (CSC) 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 |
|---|---|
CSCMatrix.from_dense() |
Construct a sparse matrix from a dense Matrix. |
CSCMatrix.to_dense() |
Convert the sparse matrix to a dense Matrix. |
CSCMatrix.to_csr() |
Convert to Compressed Sparse Row (CSRMatrix) format. |
CSCMatrix.dot_vec() |
Compute matrix-vector product. |
CSCMatrix.dot_dense() |
Compute sparse-dense matrix multiplication. |
CSCMatrix.num_rows() |
Return the number of rows. |
CSCMatrix.num_cols() |
Return the number of columns. |
CSCMatrix.num_elements() |
Return the total number of elements (rows * cols). |
CSCMatrix.shape() |
Return the (rows, cols) dimensions tuple. |
CSCMatrix.cast() |
Promotes or converts the CSCMatrix data elements to target_dtype. |
CSCMatrix.nnz() |
Return the number of stored non-zero entries. |
CSCMatrix.write_to() |
Format a human-readable string representation to a writer. |
Method Details
Section titled “Method Details”CSCMatrix.from_dense()
Section titled “CSCMatrix.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
CSCMatrix.to_dense()
Section titled “CSCMatrix.to_dense()”def to_dense(self) -> Matrix[Self.dtype]Convert the sparse matrix to a dense Matrix.
Returns: Matrix[Self.dtype]
CSCMatrix.to_csr()
Section titled “CSCMatrix.to_csr()”def to_csr(self) -> CSRMatrix[Self.dtype]Convert to Compressed Sparse Row (CSRMatrix) format.
Returns: CSRMatrix[Self.dtype]
CSCMatrix.dot_vec()
Section titled “CSCMatrix.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]]
CSCMatrix.dot_dense()
Section titled “CSCMatrix.dot_dense()”def dot_dense(self, dense: Matrix[Self.dtype]) -> Matrix[Self.dtype]Compute sparse-dense matrix multiplication.
| Parameter | Type | Description |
|---|---|---|
dense |
Matrix[Self.dtype] |
— |
Returns: Matrix[Self.dtype]
CSCMatrix.num_rows()
Section titled “CSCMatrix.num_rows()”def num_rows(self) -> IntReturn the number of rows.
Returns: Int
CSCMatrix.num_cols()
Section titled “CSCMatrix.num_cols()”def num_cols(self) -> IntReturn the number of columns.
Returns: Int
CSCMatrix.num_elements()
Section titled “CSCMatrix.num_elements()”def num_elements(self) -> IntReturn the total number of elements (rows * cols).
Returns: Int
CSCMatrix.shape()
Section titled “CSCMatrix.shape()”def shape(self) -> Tuple[Int, Int]Return the (rows, cols) dimensions tuple.
Returns: Tuple[Int, Int]
CSCMatrix.cast()
Section titled “CSCMatrix.cast()”def cast[target_dtype: DType](self) -> CSCMatrix[target_dtype]Promotes or converts the CSCMatrix data elements to target_dtype.
Returns: CSCMatrix[target_dtype]
CSCMatrix.nnz()
Section titled “CSCMatrix.nnz()”def nnz(self) -> IntReturn the number of stored non-zero entries.
Returns: Int
CSCMatrix.write_to()
Section titled “CSCMatrix.write_to()”def write_to(self, mut writer: Some[Writer])Format a human-readable string representation to a writer.