symmray.sparse.sparse_index =========================== .. py:module:: symmray.sparse.sparse_index .. autoapi-nested-parse:: Index objects for abelian arrays with block sparse backend. Classes ------- .. autoapisummary:: symmray.sparse.sparse_index.BlockIndex symmray.sparse.sparse_index.SubIndexInfo Functions --------- .. autoapisummary:: symmray.sparse.sparse_index.dicts_dont_conflict Module Contents --------------- .. py:class:: BlockIndex(chargemap=None, dual=False, subinfo=None, linearmap=None) Bases: :py:obj:`symmray.index_common.Index` An index of a block sparse, abelian symmetric tensor. This is intended to be used immutably. :param chargemap: A mapping from charge to size. :type chargemap: dict[int, int] :param dual: Whether the index is 'dual' or not, i.e. whether the flow is 'outwards' / (+ve) / ket-like = ``False`` or 'inwards' / (-ve) / bra-like = ``True``. The sign of charge contributions is then ``(-1) ** dual``. :type dual: bool, optional :param subinfo: Information about the subindices of this index and their extents if this index was formed from fusing. :type subinfo: SubIndexInfo, optional :param linearmap: If provided, a sequence of (charge, offset) pairs for a linear ordering of this index. This can be supplied instead of ``chargemap``, in which case the ``chargemap`` is built from this. If not provided, it is built on demand from ``chargemap``, assuming blocks of sorted charges. :type linearmap: Sequence[tuple[hashable, int], ...], optional .. py:attribute:: __slots__ :value: ('_chargemap', '_dual', '_subinfo', '_hashkey', '_linearmap') .. py:attribute:: _dual :value: False .. py:attribute:: _subinfo :value: None .. py:attribute:: _hashkey :value: None .. py:attribute:: _linearmap :value: None .. py:method:: to_pytree() Convert this sparse index to a pytree purely of non-symmray containers and objects. .. py:method:: from_pytree(pytree) :classmethod: Create a sparse index from a pytree purely of non-symmray containers and objects. .. py:method:: copy_with(**kwargs) A copy of this index with some attributes replaced. Note that checks are not performed on the new propoerties, this is intended for internal use. .. py:method:: to_flat() Convert this index to a flat index. .. py:property:: chargemap A mapping from charge to size. .. py:property:: linearmap A sequence of (charge, offset) pairs for each element of this index, in linear order. This is built on demand if not provided at creation. .. py:property:: subshape .. py:property:: charges The charges of this index. .. py:property:: sizes The sizes of the blocks of this index. .. py:property:: size_total The total size of this index, i.e. the sum of the sizes of all blocks. .. py:property:: num_charges The number of charges. .. py:method:: conj() A copy of this index with the dualness reversed. .. py:method:: drop_charges(charges) Return a new index with all charges in ``charges`` removed. :param charges: The charges to remove. :type charges: Sequence[hashable] :returns: A new index with the charges removed. :rtype: BlockIndex .. py:method:: select_charge(charge, subselect=None) -> BlockIndex Drop all but the specified charge from this index. :param charge: The charge to keep. :type charge: hashable :param subselect: If provided, a range of indices within the selected charge block to keep. If not provided, the entire block is kept. :type subselect: slice or array_like, optional :rtype: BlockIndex .. py:method:: size_of(c) The size of the block with charge ``c``. .. py:method:: linear_to_charge_and_offset(i) Given a linear index ``i`` into this index (as if it were a dense array), return the corresponding charge and offset within that charge block. :param i: The linear index into this index. :type i: int :returns: * **charge** (*hashable*) -- The charge corresponding to the linear index. * **offset** (*int*) -- The offset within the charge block corresponding to the linear index. .. py:method:: check() Check that the index is well-formed, i.e. all sizes are positive. .. py:method:: matches(other) Whether this index matches ``other`` index, namely, whether the ``chargemap`` of each matches, their dualnesses are opposite, and also whether their subindices match, if they have any. For debugging. :param other: The other index to compare to. :type other: BlockIndex .. py:method:: hashkey() Get a hash key for this index. .. py:method:: __hash__() :abstractmethod: .. py:method:: __str__() .. py:method:: __repr__() .. py:function:: dicts_dont_conflict(da, db) Check that two dictionaries don't conflict, i.e. they have no keys in common with different values. .. py:class:: SubIndexInfo(indices, extents) Bases: :py:obj:`symmray.index_common.SubInfo` Holder class for storing the relevant information for unfusing. :param indices: The indices (ordered) that were fused to make this index. :type indices: tuple[BlockIndex] :param extents: A mapping of each charge of the fused index to a mapping of each subsector (combination of sub charges) to the size of that subsector. This should not be mutated after creation. :type extents: dict[hashable, dict[hashable, int]] .. py:attribute:: __slots__ :value: ('_extents', '_indices', '_hashkey') .. py:attribute:: _indices .. py:attribute:: _extents .. py:attribute:: _hashkey :value: None .. py:property:: extents A mapping of each charge of the fused index to a mapping of each subsector (combination of sub charges) to the size of that subsector. .. py:property:: subshape .. py:method:: copy_with(indices=None, extents=None) A copy of this subindex information with some attributes replaced. Note that checks are not performed on the new properties, this is intended for internal use. .. py:method:: to_pytree() Convert this sparse subindex info to a pytree. .. py:method:: from_pytree(pytree) :classmethod: Build a sparse subindex info from a pytree. .. py:method:: conj() A copy of this subindex information with the relevant dualnesses reversed. .. py:method:: drop_charges(charges) Get a copy of this subindex information with the charges in ``charges`` discarded. .. py:method:: matches(other) Whether this subindex information matches ``other`` subindex information, namely, whether the ``indices`` and ``extents`` match. For debugging. .. py:method:: hashkey() Get a string hash key for this subindex information. This is cached after the first call. .. py:method:: __hash__() :abstractmethod: .. py:method:: __repr__()