symmray.sparse.sparse_index

Index objects for abelian arrays with block sparse backend.

Classes

BlockIndex

An index of a block sparse, abelian symmetric tensor. This is intended

SubIndexInfo

Holder class for storing the relevant information for unfusing.

Functions

dicts_dont_conflict(da, db)

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.Index

An index of a block sparse, abelian symmetric tensor. This is intended to be used immutably.

Parameters:
  • chargemap (dict[int, int]) – A mapping from charge to size.

  • dual (bool, optional) – 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.

  • 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 the chargemap is built from this. If not provided, it is built on demand from chargemap, 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.

to_flat()[source]

Convert this index to a flat index.

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.

conj()[source]

A copy of this index with the dualness reversed.

drop_charges(charges)[source]

Return a new index with all charges in charges removed.

Parameters:

charges (Sequence[hashable]) – The charges to remove.

Returns:

A new index with the charges removed.

Return type:

BlockIndex

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:

BlockIndex

size_of(c)[source]

The size of the block with charge c.

linear_to_charge_and_offset(i)[source]

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.

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.

check()[source]

Check that the index is well-formed, i.e. all sizes are positive.

matches(other)[source]

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.

Parameters:

other (BlockIndex) – The other index to compare to.

hashkey()[source]

Get a hash key for this index.

abstractmethod __hash__()[source]
__str__()[source]
__repr__()[source]
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.SubInfo

Holder 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.

to_pytree()[source]

Convert this sparse subindex info to a pytree.

classmethod from_pytree(pytree)[source]

Build a sparse subindex info from a pytree.

conj()[source]

A copy of this subindex information with the relevant dualnesses reversed.

drop_charges(charges)[source]

Get a copy of this subindex information with the charges in charges discarded.

matches(other)[source]

Whether this subindex information matches other subindex information, namely, whether the indices and extents match. For debugging.

hashkey()[source]

Get a string hash key for this subindex information. This is cached after the first call.

abstractmethod __hash__()[source]
__repr__()[source]