From 13c79b624e8a5b948738b9cdb2c8ba870bb6a237 Mon Sep 17 00:00:00 2001 From: raunakbhupal Date: Thu, 1 Apr 2021 23:10:46 +0530 Subject: [PATCH 1/2] Added pinv to tensorflow backend --- .../backends/tensorflow/tensorflow_backend.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tensornetwork/backends/tensorflow/tensorflow_backend.py b/tensornetwork/backends/tensorflow/tensorflow_backend.py index 0cf960838..054400dd4 100644 --- a/tensornetwork/backends/tensorflow/tensorflow_backend.py +++ b/tensornetwork/backends/tensorflow/tensorflow_backend.py @@ -430,3 +430,19 @@ def eps(self, dtype: Type[np.number]) -> float: float: Machine epsilon. """ return tf.experimental.numpy.finfo(dtype).eps + + def pinv(self, tensor: Tensor, rcond: float = 1E-15, hermitian: bool = False) -> Tensor: + """ + Compute the (Moore-Penrose) pseudo-inverse of a tensor. + Returns the pseudo-inverse of tensor. + + Args: + tensor: A tensor. + rcond: Cutoff for small singular values. + hermitian(optional): If True, matrix provided is assumed to be Hermitian (symmetric if real-valued). Defaults to False. + + Returns: + tensor: The pseudo inverse of tensor. + """ + raise NotImplementedError( + "Backend '{}' has not implemented pinv".format(self.name)) From 14016a1a328e67a948e0cdea0292a495e1e4f161 Mon Sep 17 00:00:00 2001 From: raunakbhupal Date: Fri, 2 Apr 2021 12:24:26 +0530 Subject: [PATCH 2/2] added return function to pinv --- tensornetwork/backends/tensorflow/tensorflow_backend.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tensornetwork/backends/tensorflow/tensorflow_backend.py b/tensornetwork/backends/tensorflow/tensorflow_backend.py index 054400dd4..4def9a232 100644 --- a/tensornetwork/backends/tensorflow/tensorflow_backend.py +++ b/tensornetwork/backends/tensorflow/tensorflow_backend.py @@ -444,5 +444,4 @@ def pinv(self, tensor: Tensor, rcond: float = 1E-15, hermitian: bool = False) -> Returns: tensor: The pseudo inverse of tensor. """ - raise NotImplementedError( - "Backend '{}' has not implemented pinv".format(self.name)) + return np.linalg.pinv(tensor) \ No newline at end of file