tensornetwork.BlockSparseTensor¶
-
class
tensornetwork.BlockSparseTensor(data: numpy.ndarray, charges: List[tensornetwork.block_sparse.charge.BaseCharge], flows: Union[numpy.ndarray, List[bool]], order: Optional[List[Union[List[T], numpy.ndarray]]] = None, check_consistency: Optional[bool] = False)¶ A block-sparse tensor class. This class stores non-zero elements of a symmetric tensor using an element wise encoding. The tensor data is stored in a flat np.ndarray
data. .. attribute:: * _dataAn np.ndarray containing the data of the tensor.-
* _charges A list of
BaseChargeobjects, one for each elementary leg of the tensor.
-
* _flows A list of bool, denoting the flow direction of each elementary leg.
-
* _order A list of list of int: Used to implement
reshapeandtransposeoperations. Both operations act entirely on meta-data of the tensor._orderdetermines which elemetary legs of the tensor are combined, and where they go. E.g. a tensor of rank 4 is initialized with_order=[[0],[1],[2],[3]]. Fusing legs 1 and 2 results in_order=[[0],[1,2],[3]], transposing with(1,2,0)results in_order=[[1,2],[3],[0]]. No data is shuffled during these operations.
-
__init__(data: numpy.ndarray, charges: List[tensornetwork.block_sparse.charge.BaseCharge], flows: Union[numpy.ndarray, List[bool]], order: Optional[List[Union[List[T], numpy.ndarray]]] = None, check_consistency: Optional[bool] = False) → None¶ Parameters: - data – An np.ndarray containing the actual data.
- charges – A list of
BaseChargeobjects. - flows – The flows of the tensor indices,
Falsefor inflowing,Truefor outflowing. - order – An optional order argument, determining the shape and order of the tensor.
- check_consistency – If
True, check iflen(data)is consistent with number of non-zero elements given by the charges. This usually causes significant overhead, so use only for debugging.
Methods
__init__(data, charges, flows, List[bool]], …)param data: An np.ndarray containing the actual data. conj()Complex conjugate operation. copy()Return a copy of the tensor. fromdense(indices, array)Initialize a BlockSparseTensor from a dense array. ones(indices, dtype)Initialize a symmetric tensor with ones. randn(indices, dtype)Initialize a random symmetric tensor from a random normal distribution with mean 0 and variance 1. random(indices, boundaries, float]] = (0.0, …)Initialize a random symmetric tensor from random uniform distribution. reshape(shape, int]])Reshape tensorintoshape.`ChargeArray.reshapeworks the same as the dense version, with the notable exception that the tensor can only be reshaped into a form compatible with its elementary shape.todense()Map the sparse tensor to dense storage. transpose(order, 0]), shuffle)Transpose the tensor into the new order order.BlockSparseTensor.transpose_datazeros(indices, dtype)Initialize a symmetric tensor with zeros. Attributes
TchargesA list of list of BaseCharge.dtypeThe dtype of ChargeArray.flat_chargesflat_flowsflat_orderThe flattened ChargeArray._oder.flowsA list of list of bool.ndimThe number of tensor dimensions. shapeThe dense shape of the tensor. sparse_shapeThe sparse shape of the tensor. -
conj() → tensornetwork.block_sparse.blocksparsetensor.BlockSparseTensor¶ Complex conjugate operation. :returns: The conjugated tensor :rtype: ChargeArray
-
contiguous(permutation: Union[Tuple, List[T], numpy.ndarray, None] = None, inplace: Optional[bool] = False) → Any¶ Transpose the tensor data in place such that the linear order of the elements in
BlockSparseTensor.datacorresponds to the current order of tensor indices. Consider a tensor with current order given by_order=[[1,2],[3],[0]], i.e.datawas initialized according to order [0,1,2,3], and the tensor has since been reshaped and transposed. The linear oder ofdatadoes not match the desired order [1,2,3,0] of the tensor.contiguousfixes this by permutingdatainto this order, transposing_chargesand_flows, and changing_orderto[[0,1],[2],[3]]. :param permutation: An optional alternative order to be used to transposed thetensor. IfNonedefaults toBlockSparseTensor.permutation.
-
copy() → tensornetwork.block_sparse.blocksparsetensor.BlockSparseTensor¶ Return a copy of the tensor.
-
classmethod
fromdense(indices: List[tensornetwork.block_sparse.index.Index], array: numpy.ndarray) → tensornetwork.block_sparse.blocksparsetensor.BlockSparseTensor¶ Initialize a BlockSparseTensor from a dense array. :param indices: A list of
Indexobjects. :param array: A numpy array.Returns: - A Tensor initialized from the elements
- of
arrayat the positions whereindicesfuse to the identity charge.
Return type: BlockSparseTensors
-
classmethod
ones(indices: Sequence[tensornetwork.block_sparse.index.Index], dtype: Optional[Type[numpy.number]] = None) → tensornetwork.block_sparse.blocksparsetensor.BlockSparseTensor¶ Initialize a symmetric tensor with ones. :param indices: List of
Indexobjects, one for each leg. :param dtype: An optional numpy dtype. The dtype of the tensorReturns: BlockSparseTensor
-
classmethod
randn(indices: Sequence[tensornetwork.block_sparse.index.Index], dtype: Optional[Type[numpy.number]] = None) → tensornetwork.block_sparse.blocksparsetensor.BlockSparseTensor¶ Initialize a random symmetric tensor from a random normal distribution with mean 0 and variance 1. :param indices: List of
Indexobjects, one for each leg. :param dtype: An optional numpy dtype. The dtype of the tensorReturns: BlockSparseTensor
-
classmethod
random(indices: Sequence[tensornetwork.block_sparse.index.Index], boundaries: Optional[Tuple[float, float]] = (0.0, 1.0), dtype: Optional[Type[numpy.number]] = None) → tensornetwork.block_sparse.blocksparsetensor.BlockSparseTensor¶ Initialize a random symmetric tensor from random uniform distribution. :param indices: List of
Indexobjects, one for each leg. :param boundaries: Tuple of interval boundaries for the random uniformdistribution.Parameters: dtype – An optional numpy dtype. The dtype of the tensor Returns: BlockSparseTensor
-
todense() → numpy.ndarray¶ Map the sparse tensor to dense storage.
-
classmethod
zeros(indices: Sequence[tensornetwork.block_sparse.index.Index], dtype: Optional[Type[numpy.number]] = None) → tensornetwork.block_sparse.blocksparsetensor.BlockSparseTensor¶ Initialize a symmetric tensor with zeros. :param indices: List of
Indexobjects, one for each leg. :param dtype: An optional numpy dtype. The dtype of the tensorReturns: BlockSparseTensor
-