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

Cholesky Decomposition added to decompositions.py and decompositions_test.py of both the numpy and tensorflow module. #937

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

Conversation

prat1999
Copy link

Resolved #852 . Cholesky decomposition added to both decompositions.py and decompositions_test.py of the numpy module. Further, it was added to decompositions.py and decompositions_test.py of tensorflow module.

@google-cla google-cla bot added the cla: yes label 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! After you fixed the comments this should be good to go

tensor = np.reshape(tensor, [numpy.prod(left_dims), numpy.prod(right_dims)])
n = tensor.shape[0]
m = tensor.shape[1]
if n != m:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally its always a good idea to add these types of checks! In this case however I think we can remove them because numpy already performs these kinds of checks for us.

Side note: in most cases, instead of printing a message it's better to raise an exception

self.assertEqual(L.shape, (3, 1, 3))

def test_cholesky(self):
random_matrix = np.array([[[25, 15, -5]], [[15, 18, 0]], [[-5, 0, 11]]])
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure if this is random :)

@@ -26,7 +27,7 @@ def svd(
max_truncation_error: Optional[float] = None,
relative: Optional[bool] = False) -> Tuple[Tensor, Tensor, Tensor, Tensor]:
"""Computes the singular value decomposition (SVD) of a tensor.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There are a lot of places where you add whitespace like this. Could you remove this from this PR? Thanks

resulting from combining the axes `tensor.shape[pivot_axis:]`.

For example, if `tensor` had a shape (2, 3, 4, 5) and `pivot_axis` was 2,
then `r` would have shape (2, 3, 6), and `q` would
Copy link
Collaborator

Choose a reason for hiding this comment

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

replace q and r with L and L_herm

```python
L [i1,...,iN, j] * L_trans[j, k1,...,kM] == tensor[i1,...,iN, k1,...,kM]
```
Note that the output ordering matches numpy.linalg.svd rather than tf.svd.
Copy link
Collaborator

Choose a reason for hiding this comment

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

this line can go

tf.reduce_prod(right_dims)])
n = tensor.shape[0]
m = tensor.shape[1]
tensor = tf.cast(tensor, dtype=tf.complex128, name=None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove the cast (is there are reason for this type cast? )

n = tensor.shape[0]
m = tensor.shape[1]
tensor = tf.cast(tensor, dtype=tf.complex128, name=None)
if n != m:
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove checks (tf also performs checks)

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.

Add Cholesky decomposition
2 participants