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)withmthe number of charge types, andnthe 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
typeobjects. Stored the different charge types, on for each row inunique_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 selfwithother.BaseCharge.isinrandom(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_chargesunique(return_index, return_inverse, …)Compute the unique charges in BaseCharge.Attributes
chargesBaseCharge.degeneraciesdimdtypeidentity_charges(dim)Returns the identity charge. BaseCharge.label_dtypeBaseCharge.num_symmetriesnum_uniqueReturn 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: IfTruereturn the dual charges. IfFalsereturnregular 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
selfwithother. See also np.intersect1d.Parameters: - other – A BaseCharge object.
- assume_unique – If
Trueassume 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 oftarget values withinBaseCharge.Parameters: strides – An optional stride value. Returns: charge of reduced dimension. np.ndarray: If return_locations = True; the index locationsof 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 aBaseChargeobject.Parameters: - return_index – If
True, also return the indices ofself.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 reconstructself.charges. - return_counts – If
True, also return the number of times each unique item appears inself.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_indexis True.- np.ndarray: The indices to reconstruct the original array from the
unique array. Only provided if
return_inverseis True.- np.ndarray: The number of times each of the unique values comes up in the
original array. Only provided if
return_countsis True.
Return type: - return_index – If
-