tensornetwork.BaseCharge

class tensornetwork.BaseCharge(charges: Union[List[T], numpy.ndarray], charge_labels: Optional[numpy.ndarray] = None, charge_types: Optional[List[Type[BaseCharge]]] = None, charge_dtype: Optional[Type[numpy.number]] = <class 'numpy.int16'>)

Base class for charges of BlockSparseTensor. All user defined charges should be derived from this class. .. attribute:: * unique_charges

np.ndarray of shape (m,n) with m the number of charge types, and n the number of unique charges.
* charge_labels

np.ndarray of dtype np.int16. Used for identifying charges with integer labels. `unique_charges[:, charge_labels] is the np.ndarray of actual charges.

* charge_types

A list of type objects. Stored the different charge types, on for each row in unique_charges.

__init__(charges: Union[List[T], numpy.ndarray], charge_labels: Optional[numpy.ndarray] = None, charge_types: Optional[List[Type[BaseCharge]]] = None, charge_dtype: Optional[Type[numpy.number]] = <class 'numpy.int16'>) → None

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(charges, numpy.ndarray], …) Initialize self.
copy() Return a copy of BaseCharge.
dual(take_dual) Return the charges of BaseCharge, possibly conjugated.
dual_charges(charges)
fuse(charge1, charge2)
identity_charge()
intersect(other[, assume_unique, return_indices]) Compute the intersection of self with other.
BaseCharge.isin
random(dimension, minval, maxval)
reduce(target_charges, numpy.ndarray], …) Reduce the dimension of a charge to keep only the charge values that intersect target_charges :param target_charges: array of unique charges to keep.
BaseCharge.sort_unique_charges
unique(return_index, return_inverse, …) Compute the unique charges in BaseCharge.

Attributes

charges
BaseCharge.degeneracies
dim
dtype
identity_charges(dim) Returns the identity charge.
BaseCharge.label_dtype
BaseCharge.num_symmetries
num_unique Return the number of different charges in ChargeCollection.
copy()

Return a copy of BaseCharge.

dual(take_dual: Optional[bool] = False) → tensornetwork.block_sparse.charge.BaseCharge

Return the charges of BaseCharge, possibly conjugated. :param take_dual: If True return the dual charges. If False return

regular charges.
Returns:BaseCharge
identity_charges(dim: int = 1) → tensornetwork.block_sparse.charge.BaseCharge

Returns the identity charge. :returns: The identity charge. :rtype: BaseCharge

intersect(other, assume_unique=False, return_indices=False) → Any

Compute the intersection of self with other. See also np.intersect1d.

Parameters:
  • other – A BaseCharge object.
  • assume_unique – If True assume that elements are unique.
  • return_indices – If True, return index-labels.
Returns:

BaseCharge
np.ndarray: The indices of the first occurrences of the

common values in self.

np.ndarray: The indices of the first occurrences of the

common values in other.

If return_indices=False:

BaseCharge

Return type:

If return_indices=True

num_unique

Return the number of different charges in ChargeCollection.

reduce(target_charges: Union[int, numpy.ndarray], return_locations: bool = False, strides: Optional[int] = 1) → Any

Reduce the dimension of a charge to keep only the charge values that intersect target_charges :param target_charges: array of unique charges to keep. :param return_locations: If True, also return the locations of

target values within BaseCharge.
Parameters:strides – An optional stride value.
Returns:charge of reduced dimension. np.ndarray: If return_locations = True; the index locations
of target values.
Return type:BaseCharge
unique(return_index: bool = False, return_inverse: bool = False, return_counts: bool = False) → Any

Compute the unique charges in BaseCharge. See unique for a more detailed explanation. This function does the same but instead of a np.ndarray, it returns the unique elements (not neccessarily sorted in standard order) in a BaseCharge object.

Parameters:
  • return_index – If True, also return the indices of self.charges (along the specified axis, if provided, or in the flattened array) that result in the unique array.
  • return_inverse – If True, also return the indices of the unique array (for the specified axis, if provided) that can be used to reconstruct self.charges.
  • return_counts – If True, also return the number of times each unique item appears in self.charges.
Returns:

The sorted unique values. np.ndarray: The indices of the first occurrences of the unique values

in the original array. Only provided if return_index is True.

np.ndarray: The indices to reconstruct the original array from the

unique array. Only provided if return_inverse is True.

np.ndarray: The number of times each of the unique values comes up in the

original array. Only provided if return_counts is True.

Return type:

BaseCharge