Exemple #1
0
    def zeros(cls,
              indices: Sequence[Index],
              dtype: Optional[Type[np.number]] = None) -> "BlockSparseTensor":
        """
    Initialize a symmetric tensor with zeros.
    Args:
      indices: List of `Index` objects, one for each leg. 
      dtype: An optional numpy dtype. The dtype of the tensor
    Returns:
      BlockSparseTensor
    """
        data, charges, flows, order = _data_initializer(np.zeros,
                                                        compute_num_nonzero,
                                                        indices,
                                                        dtype=dtype)

        return cls(data=data,
                   charges=charges,
                   flows=flows,
                   order=order,
                   check_consistency=False)
Exemple #2
0
 def randn(cls,
           indices: Sequence[Index],
           dtype: Optional[Type[np.number]] = None) -> "BlockSparseTensor":
     """
 Initialize a random symmetric tensor from a random normal distribution
 with mean 0 and variance 1.
 Args:
   indices: List of `Index` objects, one for each leg. 
   dtype: An optional numpy dtype. The dtype of the tensor
 Returns:
   BlockSparseTensor
 """
     data, charges, flows, order = _data_initializer(_randn,
                                                     compute_num_nonzero,
                                                     indices,
                                                     dtype=dtype)
     return cls(data=data,
                charges=charges,
                flows=flows,
                order=order,
                check_consistency=False)
Exemple #3
0
  def random(cls,
             indices: Union[Tuple[Index], List[Index]],
             boundaries: Optional[Tuple[float, float]] = (0.0, 1.0),
             dtype: Optional[Type[np.number]] = None) -> "ChargeArray":
    """
    Initialize a random ChargeArray object with data from a random 
    uniform distribution.
    Args:
      indices: List of `Index` objects.
      boundaries: Tuple of interval boundaries for the random uniform 
        distribution.
      dtype: An optional numpy dtype. The dtype of the ChargeArray
    Returns:
      ChargeArray
    """


    data, charges, flows, order = _data_initializer(
        _random, lambda charges, flows: np.prod([c.dim for c in charges]),
        indices, dtype=dtype)
    return cls(data=data, charges=charges, flows=flows, order=order)
Exemple #4
0
 def random(cls,
            indices: Sequence[Index],
            boundaries: Optional[Tuple[float, float]] = (0.0, 1.0),
            dtype: Optional[Type[np.number]] = None) -> "BlockSparseTensor":
     """
 Initialize a random symmetric tensor from random uniform distribution.
 Args:
   indices: List of `Index` objects, one for each leg. 
   boundaries: Tuple of interval boundaries for the random uniform 
     distribution.
   dtype: An optional numpy dtype. The dtype of the tensor
 Returns:
   BlockSparseTensor
 """
     data, charges, flows, order = _data_initializer(_random,
                                                     compute_num_nonzero,
                                                     indices,
                                                     dtype=dtype,
                                                     boundaries=boundaries)
     return cls(data=data,
                charges=charges,
                flows=flows,
                order=order,
                check_consistency=False)