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:: * _data

An np.ndarray containing the data of the tensor.
* _charges

A list of BaseCharge objects, 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 reshape and transpose operations. Both operations act entirely on meta-data of the tensor. _order determines 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 BaseCharge objects.
  • flows – The flows of the tensor indices, False for inflowing, True for outflowing.
  • order – An optional order argument, determining the shape and order of the tensor.
  • check_consistency – If True, check if len(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 tensor into shape.`ChargeArray.reshape works 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_data
zeros(indices, dtype) Initialize a symmetric tensor with zeros.

Attributes

T
charges A list of list of BaseCharge.
dtype The dtype of ChargeArray.
flat_charges
flat_flows
flat_order The flattened ChargeArray._oder.
flows A list of list of bool.
ndim The number of tensor dimensions.
shape The dense shape of the tensor.
sparse_shape The 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.data corresponds to the current order of tensor indices. Consider a tensor with current order given by _order=[[1,2],[3],[0]], i.e. data was initialized according to order [0,1,2,3], and the tensor has since been reshaped and transposed. The linear oder of data does not match the desired order [1,2,3,0] of the tensor. contiguous fixes this by permuting data into this order, transposing _charges and _flows, and changing _order to [[0,1],[2],[3]]. :param permutation: An optional alternative order to be used to transposed the

tensor. If None defaults to BlockSparseTensor.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 Index objects. :param array: A numpy array.

Returns:
A Tensor initialized from the elements
of array at the positions where indices fuse 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 Index objects, one for each leg. :param dtype: An optional numpy dtype. The dtype of the tensor

Returns: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 Index objects, one for each leg. :param dtype: An optional numpy dtype. The dtype of the tensor

Returns: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 Index objects, one for each leg. :param boundaries: Tuple of interval boundaries for the random uniform

distribution.
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 Index objects, one for each leg. :param dtype: An optional numpy dtype. The dtype of the tensor

Returns:BlockSparseTensor