Skip to content

qttools.datastructures.dsdbcsr#

source module qttools.datastructures.dsdbcsr

Classes

  • DSDBCSR A Distributed Stack of Distributed Block-accessible CSR matrices.

source class DSDBCSR(data: NDArray, cols: NDArray, rowptr_map: dict, 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 CSR matrices.

This DSDBSparse implementation uses a block-compressed sparse row format to store the sparsity pattern of the matrix. The data is sorted by block-row and -column. We use a row pointer map together with the column indices to access the blocks efficiently.

Note

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

Initializes the DBCSR matrix.

Parameters

  • data : NDArray The local slice of the data. This should be an array of shape (*local_stack_shape, nnz). It is the caller's responsibility to ensure that the data is distributed correctly across the ranks.

  • cols : NDArray The column indices.

  • rowptr_map : dict The row pointer map.

  • 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.

  • ltranspose Performs a local transposition of the matrix.

  • symmetrize Symmetrizes the matrix.

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

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

  • from_sparray Creates a new DSDBSparse matrix from a scipy.sparse array.

  • to_dense Converts the local data to a dense array.

source method DSDBCSR.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 DSDBCSR.ltranspose(copy=False)None | DSDBCSR

Performs a local transposition of the matrix.

Parameters

  • copy : bool, optional Whether to return a new object. Default is False.

Returns

  • None | DSDBCSR The transposed matrix. If copy is False, this is None.

Raises

  • NotImplementedError

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

Symmetrizes the matrix.

NOTE: Assumes that the matrix's sparsity pattern is symmetric.

Parameters

  • op : callable, optional The operation to perform on the symmetric elements. Default is addition.

Raises

  • NotImplementedError

source method DSDBCSR.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 classmethod DSDBCSR.zeros_like(dsdbsparse: DSDBSparse)DSDBSparse

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

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

Parameters

  • dsdbsparse : DSDBSparse The matrix to copy the shape and dtype from.

Returns

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

Creates a new DSDBSparse matrix from a scipy.sparse array.

Parameters

  • arr : sparse.spmatrix The sparse array to convert.

  • block_sizes : NDArray The size of all the blocks in the matrix.

  • global_stack_shape : tuple The global shape of the stack of matrices. The provided sparse matrix is replicated across 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

  • DSDBCSR The new DSDBCSR matrix.

source method DSDBCSR.to_dense()NDArray

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