symmray.sparse.sparse_data_common ================================= .. py:module:: symmray.sparse.sparse_data_common .. autoapi-nested-parse:: Common interface methods for arrays or vectors with block sparse backend storage. Classes ------- .. autoapisummary:: symmray.sparse.sparse_data_common.BlockCommon Functions --------- .. autoapisummary:: symmray.sparse.sparse_data_common._identity Module Contents --------------- .. py:function:: _identity(x) .. py:class:: BlockCommon Mixin class for arrays consisting of dicts of blocks. .. py:attribute:: __slots__ :value: ('_blocks',) .. py:method:: _init_blockcommon(blocks) .. py:method:: _new_with_blockcommon(blocks) .. py:method:: _copy_blockcommon() .. py:method:: _copy_with_blockcommon(blocks=None) .. py:method:: _modify_blockcommon(blocks=None) .. py:method:: _to_pytree_blockcommon() .. py:property:: blocks The blocks of the array. .. py:method:: get_block(sector) Get the block for the given sector. .. py:method:: set_block(sector, block) Set the block for the given sector. .. py:method:: del_block(sector) Delete the block for the given sector. .. py:method:: get_sector_block_pairs() Get an iterator over all `(sector, block)` pairs. .. py:method:: get_all_blocks() Get an iterator over all blocks of the array. .. py:method:: _map_blocks_blockcommon(fn_block=None, fn_sector=None, fn_filter=None) Map the blocks and their keys (sectors) of the array inplace. .. py:method:: get_any_sector() .. py:method:: get_any_array() Get any array from the blocks, to check type and backend for example. .. py:method:: get_namespace() Get the array namespace for the underlying blocks. .. py:method:: get_scalar_element() Assuming the block array is a scalar, get that scalar element. .. py:method:: is_zero(tol=1e-12) Check if all blocks are zero up to a tolerance. .. py:property:: dtype Get the dtype name from an arbitrary block in the array. .. py:property:: backend Get the backend name from an arbitrary block in the array. .. py:property:: num_blocks The number of blocks in the array. .. py:property:: sectors Get the sectors, i.e. keys of the blocks. .. py:method:: has_sector(sector) Check if the array has a block for the given sector. .. py:method:: get_params() Get the parameters of this block array as a pytree (dict). :rtype: dict[tuple, array_like] .. py:method:: set_params(params) Set the parameters of this block array from a pytree (dict). :param params: :type params: dict[tuple, array_like] .. py:method:: apply_to_arrays(fn) Apply the ``fn`` inplace to the array of every block. .. py:method:: item() Convert block array to a scalar if it is a scalar block array. .. py:method:: _binary_blockwise_op_abelian(other, fn, missing=None, inplace=False) Apply a binary blockwise operation to two block arrays, which must have exactly the same sectors/keys, depending on `missing`. :param fn: Function to apply to the blocks of the arrays, with signature ``fn(x_block, y_block) -> result_block``. :type fn: callable :param x: First block array. :type x: BlockCommon :param y: Second block array. :type y: BlockCommon :param missing: 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. :type missing: str, optional :param inplace: Whether to modify the first array in place. Default is False. :type inplace: bool, optional :rtype: BlockCommon .. py:method:: _do_reduction(fn) Perform (associative) reduction operation on blocks of the array. .. py:method:: norm() Get the frobenius norm of the block array. .. py:method:: _allclose_blockcommon(other, **allclose_opts) .. py:method:: _test_allclose_blockcommon(other, **allclose_opts) Like `allclose` but raises an AssertionError with details if not close.