Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds pinv to tensorflow backend (https://github.com/google/TensorNetwork/issues/844) #935

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

krbhanushali
Copy link

@krbhanushali krbhanushali commented Aug 31, 2021

Added pinv to tensorflow_backend.py and corresponding tests to tensorflow_backend_tests,py Issue: #844

@google-cla google-cla bot added the cla: yes label Aug 31, 2021
@krbhanushali krbhanushali mentioned this pull request Aug 31, 2021
Copy link
Collaborator

@mganahl mganahl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, looks good! Could you also add pinv to the AbstractBackend class, as well as numpy and jax backends?

np.testing.assert_allclose(expected, actual)
expected = tf.linalg.pinv(tensor)
actual = backend.pinv(tensor)
np.testing.assert_allclose(expected, actual)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a test that actual @ tensor and tensor @ actual equal the identity (within the desired error)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would testing for all the criteria in https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_inverse be a better test? (As for an example given in tf's documentation, the product wasn't identity)

@@ -430,3 +430,26 @@ 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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove the hermitian argument

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had included it as it was an argument for numpy. I'll remove it in the next commit.
Thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants