Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def zeros(self,
shape: Tuple[int, ...],
dtype: Optional[Type[np.number]] = None) -> Tensor:
return ShellTensor(shape)
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.')
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)
def convert_to_tensor(self, tensor: Any) -> Tensor:
shell_tensor = ShellTensor(tuple(tensor.shape))
return shell_tensor
def eigh(self, matrix: Tensor) -> Tuple[Tensor, Tensor]:
shape = matrix.shape
return ShellTensor((shape[0],)), ShellTensor(shape)
def multiply(self, tensor1: Tensor, tensor2: Tensor) -> Tensor:
a = np.ones(tensor1.shape)
b = np.ones(tensor2.shape)
return ShellTensor((a * b).shape)
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.')
def randn(self,
shape: Tuple[int, ...],
dtype: Optional[Type[np.number]] = None,
seed: Optional[int] = None) -> Tensor:
return ShellTensor(shape)
def trace(self, tensor: Tensor) -> Tensor:
return ShellTensor(tensor.shape[:-2])
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)