symmray.sparse.sparse_index¶
Index objects for abelian arrays with block sparse backend.
Classes¶
An index of a block sparse, abelian symmetric tensor. This is intended |
|
Holder class for storing the relevant information for unfusing. |
Functions¶
|
Check that two dictionaries don't conflict, i.e. they have no keys in |
Module Contents¶
- class symmray.sparse.sparse_index.BlockIndex(chargemap=None, dual=False, subinfo=None, linearmap=None)[source]¶
Bases:
symmray.index_common.IndexAn index of a block sparse, abelian symmetric tensor. This is intended to be used immutably.
- Parameters:
dual (bool, optional) – Whether the index is ‘dual’ or not, i.e. whether the flow is ‘outwards’ / (+ve) / ket-like =
Falseor ‘inwards’ / (-ve) / bra-like =True. The sign of charge contributions is then(-1) ** dual.subinfo (SubIndexInfo, optional) – Information about the subindices of this index and their extents if this index was formed from fusing.
linearmap (Sequence[tuple[hashable, int], ...], optional) – 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 thechargemapis built from this. If not provided, it is built on demand fromchargemap, assuming blocks of sorted charges.
- __slots__ = ('_chargemap', '_dual', '_subinfo', '_hashkey', '_linearmap')¶
- _dual = False¶
- _subinfo = None¶
- _hashkey = None¶
- _linearmap = None¶
- to_pytree()[source]¶
Convert this sparse index to a pytree purely of non-symmray containers and objects.
- classmethod from_pytree(pytree)[source]¶
Create a sparse index from a pytree purely of non-symmray containers and objects.
- copy_with(**kwargs)[source]¶
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.
- property chargemap¶
A mapping from charge to size.
- 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.
- property subshape¶
- property charges¶
The charges of this index.
- property sizes¶
The sizes of the blocks of this index.
- property size_total¶
The total size of this index, i.e. the sum of the sizes of all blocks.
- property num_charges¶
The number of charges.
- drop_charges(charges)[source]¶
Return a new index with all charges in
chargesremoved.- Parameters:
charges (Sequence[hashable]) – The charges to remove.
- Returns:
A new index with the charges removed.
- Return type:
- select_charge(charge, subselect=None) BlockIndex[source]¶
Drop all but the specified charge from this index.
- Parameters:
charge (hashable) – The charge to keep.
subselect (slice or array_like, optional) – If provided, a range of indices within the selected charge block to keep. If not provided, the entire block is kept.
- Return type:
- linear_to_charge_and_offset(i)[source]¶
Given a linear index
iinto this index (as if it were a dense array), return the corresponding charge and offset within that charge block.- Parameters:
i (int) – The linear index into this index.
- Returns:
charge (hashable) – The charge corresponding to the linear index.
offset (int) – The offset within the charge block corresponding to the linear index.
- matches(other)[source]¶
Whether this index matches
otherindex, namely, whether thechargemapof each matches, their dualnesses are opposite, and also whether their subindices match, if they have any. For debugging.- Parameters:
other (BlockIndex) – The other index to compare to.
- symmray.sparse.sparse_index.dicts_dont_conflict(da, db)[source]¶
Check that two dictionaries don’t conflict, i.e. they have no keys in common with different values.
- class symmray.sparse.sparse_index.SubIndexInfo(indices, extents)[source]¶
Bases:
symmray.index_common.SubInfoHolder class for storing the relevant information for unfusing.
- Parameters:
indices (tuple[BlockIndex]) – The indices (ordered) that were fused to make this index.
extents (dict[hashable, dict[hashable, int]]) – 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.
- __slots__ = ('_extents', '_indices', '_hashkey')¶
- _indices¶
- _extents¶
- _hashkey = None¶
- 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.
- property subshape¶
- copy_with(indices=None, extents=None)[source]¶
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.
- drop_charges(charges)[source]¶
Get a copy of this subindex information with the charges in
chargesdiscarded.
- matches(other)[source]¶
Whether this subindex information matches
othersubindex information, namely, whether theindicesandextentsmatch. For debugging.