symmray.sparse.sparse_data_common

Common interface methods for arrays or vectors with block sparse backend storage.

Classes

BlockCommon

Mixin class for arrays consisting of dicts of blocks.

Functions

Module Contents

symmray.sparse.sparse_data_common._identity(x)[source]
class symmray.sparse.sparse_data_common.BlockCommon[source]

Mixin class for arrays consisting of dicts of blocks.

__slots__ = ('_blocks',)
_init_blockcommon(blocks)[source]
_new_with_blockcommon(blocks)[source]
_copy_blockcommon()[source]
_copy_with_blockcommon(blocks=None)[source]
_modify_blockcommon(blocks=None)[source]
_to_pytree_blockcommon()[source]
property blocks

The blocks of the array.

get_block(sector)[source]

Get the block for the given sector.

set_block(sector, block)[source]

Set the block for the given sector.

del_block(sector)[source]

Delete the block for the given sector.

get_sector_block_pairs()[source]

Get an iterator over all (sector, block) pairs.

get_all_blocks()[source]

Get an iterator over all blocks of the array.

_map_blocks_blockcommon(fn_block=None, fn_sector=None, fn_filter=None)[source]

Map the blocks and their keys (sectors) of the array inplace.

get_any_sector()[source]
get_any_array()[source]

Get any array from the blocks, to check type and backend for example.

get_namespace()[source]

Get the array namespace for the underlying blocks.

get_scalar_element()[source]

Assuming the block array is a scalar, get that scalar element.

is_zero(tol=1e-12)[source]

Check if all blocks are zero up to a tolerance.

property dtype

Get the dtype name from an arbitrary block in the array.

property backend

Get the backend name from an arbitrary block in the array.

property num_blocks

The number of blocks in the array.

property sectors

Get the sectors, i.e. keys of the blocks.

has_sector(sector)[source]

Check if the array has a block for the given sector.

get_params()[source]

Get the parameters of this block array as a pytree (dict).

Return type:

dict[tuple, array_like]

set_params(params)[source]

Set the parameters of this block array from a pytree (dict).

Parameters:

params (dict[tuple, array_like])

apply_to_arrays(fn)[source]

Apply the fn inplace to the array of every block.

item()[source]

Convert block array to a scalar if it is a scalar block array.

_binary_blockwise_op_abelian(other, fn, missing=None, inplace=False)[source]

Apply a binary blockwise operation to two block arrays, which must have exactly the same sectors/keys, depending on missing.

Parameters:
  • fn (callable) – Function to apply to the blocks of the arrays, with signature fn(x_block, y_block) -> result_block.

  • x (BlockCommon) – First block array.

  • y (BlockCommon) – Second block array.

  • missing (str, optional) – How to handle missing blocks. Can be “outer”, “inner” or None. Default is None which requires 1:1 matching blocks. If missing “outer” is specified, blocks present in only one of either array are simply kept. If missing “inner” is specified, blocks present in only one of either array are simply dropped.

  • inplace (bool, optional) – Whether to modify the first array in place. Default is False.

Return type:

BlockCommon

_do_reduction(fn)[source]

Perform (associative) reduction operation on blocks of the array.

norm()[source]

Get the frobenius norm of the block array.

_allclose_blockcommon(other, **allclose_opts)[source]
_test_allclose_blockcommon(other, **allclose_opts)[source]

Like allclose but raises an AssertionError with details if not close.