How to use the tensornetwork.backends.shell.shell_backend.ShellTensor function in tensornetwork

To help you get started, we’ve selected a few tensornetwork examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / TensorNetwork / tensornetwork / backends / shell / shell_backend.py View on Github external
def zeros(self,
            shape: Tuple[int, ...],
            dtype: Optional[Type[np.number]] = None) -> Tensor:

    return ShellTensor(shape)
github google / TensorNetwork / tensornetwork / backends / shell / shell_backend.py View on Github external
if (initial_state is not None) and hasattr(A, 'shape'):
      if initial_state.shape != A.shape[1]:
        raise ValueError(
            "A.shape[1]={} and initial_state.shape={} are incompatible.".format(
                A.shape[1], initial_state.shape))

    if initial_state is None:
      if not hasattr(A, 'shape'):
        raise AttributeError("`A` has no  attribute `shape`. Cannot initialize "
                             "lanczos. Please provide a valid `initial_state`")
      return [ShellTensor(tuple()) for _ in range(numeig)
             ], [ShellTensor((A.shape[0],)) for _ in range(numeig)]

    if initial_state is not None:
      return [ShellTensor(tuple()) for _ in range(numeig)
             ], [ShellTensor(initial_state.shape) for _ in range(numeig)]

    raise ValueError(
        '`A` has no attribut shape and no `initial_state` is given.')
github google / TensorNetwork / tensornetwork / backends / shell / shell_backend.py View on Github external
def concat(self, values: Sequence[Tensor], axis: int) -> Tensor:
    shape = values[0].shape
    if axis < 0:
      axis += len(shape)
    concat_size = sum(v.shape[axis] for v in values)
    new_shape = shape[:axis] + (concat_size,) + shape[axis + 1:]
    return ShellTensor(new_shape)
github google / TensorNetwork / tensornetwork / backends / shell / shell_backend.py View on Github external
def convert_to_tensor(self, tensor: Any) -> Tensor:
    shell_tensor = ShellTensor(tuple(tensor.shape))
    return shell_tensor
github google / TensorNetwork / tensornetwork / backends / shell / shell_backend.py View on Github external
def eigh(self, matrix: Tensor) -> Tuple[Tensor, Tensor]:
    shape = matrix.shape
    return ShellTensor((shape[0],)), ShellTensor(shape)
github google / TensorNetwork / tensornetwork / backends / shell / shell_backend.py View on Github external
def multiply(self, tensor1: Tensor, tensor2: Tensor) -> Tensor:
    a = np.ones(tensor1.shape)
    b = np.ones(tensor2.shape)
    return ShellTensor((a * b).shape)
github google / TensorNetwork / tensornetwork / backends / shell / shell_backend.py View on Github external
raise ValueError(
          "Got numeig = {} > 1 and `reorthogonalize = False`. "
          "Use `reorthogonalize=True` for `numeig > 1`".format(numeig))

    if (initial_state is not None) and hasattr(A, 'shape'):
      if initial_state.shape != A.shape[1]:
        raise ValueError(
            "A.shape[1]={} and initial_state.shape={} are incompatible.".format(
                A.shape[1], initial_state.shape))

    if initial_state is None:
      if not hasattr(A, 'shape'):
        raise AttributeError("`A` has no  attribute `shape`. Cannot initialize "
                             "lanczos. Please provide a valid `initial_state`")
      return [ShellTensor(tuple()) for _ in range(numeig)
             ], [ShellTensor(A.shape[0]) for _ in range(numeig)]

    if initial_state is not None:
      return [ShellTensor(tuple()) for _ in range(numeig)
             ], [ShellTensor(initial_state.shape) for _ in range(numeig)]

    raise ValueError(
        '`A` has no attribut shape adn no `initial_state` is given.')
github google / TensorNetwork / tensornetwork / backends / shell / shell_backend.py View on Github external
def randn(self,
            shape: Tuple[int, ...],
            dtype: Optional[Type[np.number]] = None,
            seed: Optional[int] = None) -> Tensor:
    return ShellTensor(shape)
github google / TensorNetwork / tensornetwork / backends / shell / shell_backend.py View on Github external
def trace(self, tensor: Tensor) -> Tensor:
    return ShellTensor(tensor.shape[:-2])
github google / TensorNetwork / tensornetwork / backends / shell / shell_backend.py View on Github external
def inv(self, matrix: Tensor) -> Tensor:
    if len(matrix.shape) > 2:
      raise ValueError(
          "input to shell backend method `inv` has shape {}. Only matrices are supported."
          .format(matrix.shape))
    return ShellTensor(matrix.shape)