dsdbcsr#
Includes the distributed block-accessible CSR matrix data structure.
Classes:
-
DSDBCSR–A Distributed Stack of Distributed Block-accessible CSR matrices.
DSDBCSR
#
DSDBCSR(dtype: dtype[generic], cols: NDArray, rowptr_map: dict, block_sizes: NDArray, local_stack_shape: tuple | int, global_stack_shape: tuple, symmetry: str | None = None)
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.
Parameters:
-
dtype(dtype[generic]) –The data type of the matrix.
-
cols(NDArray) –The column indices.
-
rowptr_map(dict) –The row pointer map.
-
block_sizes(NDArray) –The size of each block in the sparse matrix.
-
local_stack_shape(tuple or int) –The local shape of the stack. If this is an integer, it is interpreted as a one-dimensional stack.
-
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.
-
symmetry(str | None, default:None) –The symmetry of the matrix. This can be "symmetric", "hermitian", "skew-symmetric", "skew-hermitian", or None. Default is None.
Methods:
-
block_sizes–Sets new block sizes for the matrix.
-
symmetrize–Symmetrizes the matrix with a given symmetry.
-
spy–Returns the row and column indices of the non-zero elements.
-
empty_like–Creates a new DSDBCSR matrix with the same shape and dtype.
-
from_sparray–Creates a new DSDBCSR matrix from a scipy.sparse array.
-
to_dense–Converts the local data to a dense array.
block_sizes
#
Sets new block sizes for the matrix.
Parameters:
-
block_sizes(NDArray) –The new block sizes.
symmetrize
#
symmetrize(symmetry: str) -> None
Symmetrizes the matrix with a given symmetry.
Note
This assumes that the matrix's sparsity pattern is symmetric.
Parameters:
-
symmetry(str) –The symmetry to enforce. This can be "symmetric", "hermitian", "skew-symmetric", or "skew-hermitian".
spy
#
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.
Note
In the block distributed case, this returns the local sparsity pattern.
Warning
This not performant.
Returns:
-
rows(NDArray) –Row indices of the non-zero elements.
-
cols(NDArray) –Column indices of the non-zero elements.
empty_like
classmethod
#
from_sparray
classmethod
#
from_sparray(sparray: spmatrix, block_sizes: NDArray, global_stack_shape: tuple, symmetry: str | None = None, dtype: dtype[generic] = complex128, allocate: bool = True) -> DSDBCSR
Creates a new DSDBCSR matrix from a scipy.sparse array.
This essentially distributed the matrix across the stack and block communicators.
Parameters:
-
sparray(spmatrix) –The sparse matrix from which to use the sparsity pattern.
-
block_sizes(NDArray) –The block sizes of the block-sparse matrix.
-
global_stack_shape(tuple) –The global shape of the stack.
-
symmetry(str | None, default:None) –The symmetry of the matrix. This can be "symmetric", "hermitian", "skew-symmetric", "skew-hermitian", or None. Default is None.
-
dtype(dtype, default:complex128) –The data type of the matrix. Default is
xp.complex128. -
allocate(bool, default:True) –Whether to allocate the data of the resulting matrix. Default is True.
Returns:
-
DSDBCSR–The new DSDBCSR matrix.
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).