Skip to content

qttools.datastructures.dsdbcoo#

source module qttools.datastructures.dsdbcoo

Classes

  • DSDBCOO A Distributed Stack of Distributed Block-accessible COO matrices.

source class DSDBCOO(data: NDArray, rows: NDArray, cols: NDArray, block_sizes: NDArray, global_stack_shape: tuple, return_dense: bool = True, symmetry: bool | None = False, symmetry_op: Callable = xp.conj)

Bases : DSDBSparse

A Distributed Stack of Distributed Block-accessible COO matrices.

Note

It is the caller's responsibility to ensure that the data is distributed correctly across the ranks.

Initializes a DSDBCOO matrix.

Parameters

  • data : NDArray The local slice of the data. This should be an array of shape (*local_stack_shape, local_nnz).

  • rows : NDArray The local row indices of the COO matrix.

  • cols : NDArray The local column indices of the COO matrix.

  • block_sizes : NDArray The size of each block in the sparse matrix.

  • global_stack_shape : tuple or int The global shape of the stack. If this is an integer, it is interpreted as a one-dimensional stack.

  • return_dense : bool, optional Whether to return dense arrays when accessing the blocks. Default is True.

  • symmetry : bool, optional Whether the matrix is symmetric. Default is False.

  • symmetry_op : callable, optional The operation to use for the symmetry. Default is xp.conj.

Attributes

  • block_offsets : ArrayLike Returns the block sizes.

  • blocks : _DSDBlockIndexer Returns a block indexer.

  • sparse_blocks : _DSDBlockIndexer Returns a block indexer.

  • stack : _DStackIndexer Returns a stack indexer.

  • data : NDArray Returns the local slice of the data, masking the padding.

Methods

  • block_sizes Sets new block sizes for the matrix.

  • spy Returns the row and column indices of the non-zero elements.

  • symmetrize Symmetrizes the matrix with a given operation.

  • zeros_like Creates a new DSDBCOO matrix with the same shape and dtype.

  • from_sparray Constructs a DSDBCOO matrix from a COO matrix.

  • to_dense Converts the local data to a dense array.

source method DSDBCOO.block_sizes(block_sizes: NDArray)None

Sets new block sizes for the matrix.

Parameters

  • block_sizes : NDArray The new block sizes.

Raises

  • NotImplementedError

  • ValueError

source method DSDBCOO.spy()tuple[NDArray, NDArray]

Returns the row and column indices of the non-zero elements.

This is essentially the same as converting the sparsity pattern to coordinate format. The returned sparsity pattern is not sorted.

Returns

  • rows : NDArray Row indices of the non-zero elements.

  • cols : NDArray Column indices of the non-zero elements.

source method DSDBCOO.symmetrize(op: Callable[[NDArray, NDArray], NDArray] = xp.add)None

Symmetrizes the matrix with a given operation.

This is done by setting the data to the result of the operation applied to the data and its conjugate transpose.

Note

This assumes that the matrix's sparsity pattern is symmetric.

Parameters

  • op : callable, optional The operation to apply to the data and its conjugate transpose. Default is xp.add, so that the matrix is Hermitian after calling.

Raises

  • NotImplementedError

source classmethod DSDBCOO.zeros_like(dsdbsparse: DSDBCOO)DSDBCOO

Creates a new DSDBCOO matrix with the same shape and dtype.

All non-zero elements are set to zero, but the sparsity pattern is preserved.

Parameters

  • dsdbcoo : DSDBCOO The matrix to copy the shape and dtype from.

Returns

  • dsdbcoo The new DSDBCOO matrix.

Raises

  • ValueError

source classmethod DSDBCOO.from_sparray(sparray: sparse.spmatrix, block_sizes: NDArray, global_stack_shape: tuple, symmetry: bool | None = False, symmetry_op: Callable = xp.conj)DSDBCOO

Constructs a DSDBCOO matrix from a COO matrix.

This essentially distributes the COO matrix across the participating ranks.

Parameters

  • sparray : sparse.coo_matrix The COO matrix to distribute.

  • block_sizes : NDArray The block sizes of the block-sparse matrix.

  • global_stack_shape : tuple The global shape of the stack.

  • symmetry : bool, optional Whether to enforce symmetry in the matrix. Default is False.

  • symmetry_op : callable, optional The operation to use for the symmetry. Default is xp.conj.

Returns

  • DSDBCOO The new DSDBCOO matrix.

Raises

  • ValueError

source method DSDBCOO.to_dense()

Converts the local data to a dense array.

This is dumb, unless used for testing and debugging.

Returns

  • arr : NDArray The dense array of shape (*local_stack_shape, *shape).

Raises

  • ValueError