Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Add power function and test to backend #846

Merged
merged 2 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tensornetwork/backends/abstract_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,3 +988,16 @@ def deserialize_tensor(self, s: str) -> Tensor:
raise NotImplementedError(
"Backend '{}' has not implemented deserialize_tensor.".format(
self.name))

def power(self, a: Tensor, b: Tensor) -> Tensor:
wkostuch marked this conversation as resolved.
Show resolved Hide resolved
"""
Returns the element-wise exponentiation of tensor a raised to tensor b.

Args:
a: The tensor containing the bases.
alewis marked this conversation as resolved.
Show resolved Hide resolved
b: The tensor containing the powers.

Returns:
The tensor that is each element of a raised to the corresponding power in b.
wkostuch marked this conversation as resolved.
Show resolved Hide resolved
"""
raise NotImplementedError(f"Backend {self.name} has not implemented power.")
wkostuch marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions tensornetwork/backends/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,8 @@ def test_pivot_not_implemented():
backend = AbstractBackend()
with pytest.raises(NotImplementedError):
backend.pivot(np.ones((2, 2)))

def test_power_not_implemented():
backend = AbstractBackend()
with pytest.raises(NotImplementedError):
backend.power(np.array([1, 2]), np.array([1, 2]))
wkostuch marked this conversation as resolved.
Show resolved Hide resolved