lacuna.sparse.base#

Base classes for sparse arrays and matrices.

These classes define the minimal interface shared by concrete sparse types in lacuna.sparse, including shape/dtype bookkeeping and basic materialization.

Classes

SparseArray(shape[, dtype])

Abstract base class for sparse N-dimensional arrays.

SparseMatrix(shape[, dtype])

Abstract base class for 2D sparse matrices.

class lacuna.sparse.base.SparseArray(shape, dtype=None)[source]#

Bases: object

Abstract base class for sparse N-dimensional arrays.

Parameters:
  • shape (tuple[int, ...]) – Array shape. Stored as a tuple.

  • dtype (Any, optional) – Element dtype metadata (informational for base class).

shape#

Array shape.

Type:

tuple[int, …]

ndim#

Number of dimensions, equal to len(shape).

Type:

int

dtype#

Element type metadata.

Type:

Any

class lacuna.sparse.base.SparseMatrix(shape, dtype=None)[source]#

Bases: SparseArray

Abstract base class for 2D sparse matrices.

Parameters:
  • shape (tuple[int, int]) – Matrix shape. Must be two-dimensional.

  • dtype (Any, optional) – Element dtype metadata.

Raises:

ValueError – If shape is not 2D.

toarray()[source]#

Return a dense numpy.ndarray with the same shape and dtype.

Notes

The base implementation returns an all-zeros array. Concrete sparse matrix types should override this to materialize actual data.