Skip to content

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 CSCMatrix

Compressed Sparse Column (CSC) 2D matrix format.


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 —

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.

def from_dense(dense: Matrix[Self.dtype]) -> Self

Construct a sparse matrix from a dense Matrix.

Parameter Type Description
dense Matrix[Self.dtype] —

Returns: Self


def to_dense(self) -> Matrix[Self.dtype]

Convert the sparse matrix to a dense Matrix.

Returns: Matrix[Self.dtype]


def to_csr(self) -> CSRMatrix[Self.dtype]

Convert to Compressed Sparse Row (CSRMatrix) format.

Returns: CSRMatrix[Self.dtype]


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]]


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]


def num_rows(self) -> Int

Return the number of rows.

Returns: Int


def num_cols(self) -> Int

Return the number of columns.

Returns: Int


def num_elements(self) -> Int

Return the total number of elements (rows * cols).

Returns: Int


def shape(self) -> Tuple[Int, Int]

Return the (rows, cols) dimensions tuple.

Returns: Tuple[Int, Int]


def cast[target_dtype: DType](self) -> CSCMatrix[target_dtype]

Promotes or converts the CSCMatrix data elements to target_dtype.

Returns: CSCMatrix[target_dtype]


def nnz(self) -> Int

Return the number of stored non-zero entries.

Returns: Int


def write_to(self, mut writer: Some[Writer])

Format a human-readable string representation to a writer.