lacuna.sparse.csc#

Classes

CSC(indptr, indices, data, shape[, dtype, check])

Compressed Sparse Column (CSC) matrix.

class lacuna.sparse.csc.CSC(indptr, indices, data, shape, dtype=<class 'numpy.float64'>, check=True)[source]#

Bases: SparseMatrix

Compressed Sparse Column (CSC) matrix.

Parameters:
  • indptr (array_like of int64, shape (ncols + 1,)) – Column pointer array.

  • indices (array_like of int64, shape (nnz,)) – Row indices of nonzero values.

  • data (array_like of float64, shape (nnz,)) – Nonzero values.

  • shape (tuple of int) – Matrix shape (nrows, ncols).

  • dtype (numpy.dtype, optional) – Value dtype, defaults to np.float64.

  • check (bool, optional) – If True, validate invariants in the native layer (may be slower).

indptr, indices, data

Storage arrays for CSC structure and values.

Type:

numpy.ndarray

shape#

Matrix dimensions.

Type:

tuple[int, int]

dtype#

Value dtype.

Type:

numpy.dtype

nnz#

Number of stored elements.

Type:

int

Notes

Backed by Rust kernels through lacuna._core.Csc64; operations release the GIL.

Examples

Construct a small CSC and run basic ops:

>>> import numpy as np
>>> from lacuna.sparse import CSC
>>> indptr = np.array([0, 1, 2, 3])
>>> indices = np.array([0, 1, 1])
>>> data = np.array([1.0, 2.0, 3.0])
>>> a = CSC(indptr, indices, data, shape=(2, 3))
>>> a.nnz
3
>>> (a @ np.array([1.0, 0.0, 1.0])).tolist()  # SpMV
[1.0, 3.0]
>>> a.sum()
6.0
property T#
eliminate_zeros()[source]#

Remove explicit zeros. Returns a new CSC.

classmethod from_arrays(indptr, indices, data, shape, check=True)[source]#

Construct from CSC arrays.

Parameters:
  • indptr (array_like) – CSC structure and values.

  • indices (array_like) – CSC structure and values.

  • data (array_like) – CSC structure and values.

  • shape (tuple[int, int]) – Matrix shape.

  • check (bool, optional) – Validate invariants in the native layer.

multiply(other)[source]#

Hadamard (elementwise) product with another CSC.

property nnz#

Number of stored values.

prune(eps)[source]#

Drop entries with abs(value) <= eps. Returns a new CSC.

sum(axis=None)[source]#

Sum of entries.

Parameters:

axis ({None, 0, 1}, optional) – None for global sum; 0 for column sums; 1 for row sums.

toarray()[source]#

Convert to a dense NumPy ndarray of shape (nrows, ncols).