This repository has been archived by the owner on Nov 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 359
Implemented Cholesky decomposition to numpy and tensorflow backends #890
Open
LuiGiovanni
wants to merge
29
commits into
google:master
Choose a base branch
from
LuiGiovanni:CholeskyDecomposition
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
016d654
Added power to Jax backend and test
LuiGiovanni 62a06c0
Added power function to the Jax backend and test.
LuiGiovanni 43952dd
Fixed white space error.
LuiGiovanni b0f579e
Re-made the power test function.
LuiGiovanni e9f9869
Fixed typo
LuiGiovanni 9e16a9f
Testing out numpy square.
LuiGiovanni 81b4d8b
Fixed issues with the assertion in test, should work now.
LuiGiovanni 195f691
Added NotImplementedError function and it's respective test for Chols…
LuiGiovanni 737f071
Fixed line too long error
LuiGiovanni 0fbe8fb
Removing changes for different branches.
LuiGiovanni 8c37656
Revert "Fixed issues with the assertion in test, should work now."
LuiGiovanni a894960
Fixed a few pylint issues, should work now
LuiGiovanni 3ba747f
Fixed typo in the error message
LuiGiovanni a112ebe
Merge branch 'master' into CholeskyDecomposition
alewis f9fb40d
Renamed cholesky function, to a shorter name
LuiGiovanni 4b4ece6
Merge branch 'CholeskyDecomposition' of https://github.com/LuiGiovann…
LuiGiovanni 0c3817d
Renamed cholesky function from cholesky_decomposition to cholesky
LuiGiovanni aedfe2a
Implemented Cholesky to numpy and tensorflow with their respective tests
LuiGiovanni 13026b5
Fixed pylint issues
LuiGiovanni 11eba6a
Implemented Cholesky decomposition to tensorflow, numpy & pytorch bac…
LuiGiovanni 4da6eac
Fixed minor pylint issues
LuiGiovanni 6548989
Merge branch 'master' into CholeskyDecomposition
mganahl 66b5b94
Merge branch 'master' into CholeskyDecomposition
mganahl dab2060
requested changes made removed unnecessary arguments and better matrix
LuiGiovanni e6b9c08
Merge branch 'CholeskyDecomposition' of https://github.com/LuiGiovann…
LuiGiovanni 367ce3d
Fixed commented testing functions
LuiGiovanni 92c931a
Merge branch 'master' into CholeskyDecomposition
mganahl a51cb9a
Merge branch 'master' into CholeskyDecomposition
mganahl 2b269e0
Merge branch 'master' into CholeskyDecomposition
mganahl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ | |
import numpy as np | ||
import tensorflow as tf | ||
from tensornetwork.backends.numpy import decompositions | ||
import pytest | ||
|
||
np_dtypes = [np.float64, np.complex128] | ||
|
||
class DecompositionsTest(tf.test.TestCase): | ||
|
||
|
@@ -52,6 +54,13 @@ def test_qr(self): | |
q, r = decompositions.qr(np, random_matrix, 1, non_negative_diagonal) | ||
self.assertAllClose(q.dot(r), random_matrix) | ||
|
||
def test_cholesky(self): | ||
#Assured positive-definite hermitian matrixs | ||
random_matrix = np.random.rand(10, 10) | ||
random_matrix = random_matrix @ random_matrix.T.conj() | ||
L = decompositions.cholesky(tf, random_matrix, 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are passing the tensorflow module here, but it should be numpy |
||
self.assertAllClose(np.linalg.cholesky(random_matrix), L) | ||
|
||
def test_max_singular_values(self): | ||
random_matrix = np.random.rand(10, 10) | ||
unitary1, _, unitary2 = np.linalg.svd(random_matrix) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,23 @@ def svd( | |
return u, s, vh, s_rest | ||
|
||
|
||
def cholesky( | ||
torch: Any, | ||
tensor: Tensor, | ||
pivot_axis: int | ||
) -> Tuple[Tensor, Tensor]: | ||
""" | ||
Computes the Cholesky decomposition of a tensor | ||
|
||
See tensornetwork.backends.tensorflow.decompositions for details. | ||
""" | ||
left_dims = list(tensor.shape)[:pivot_axis] | ||
right_dims = list(tensor.shape)[pivot_axis:] | ||
|
||
tensor = torch.reshape(tensor, (np.prod(left_dims), np.prod(right_dims))) | ||
L = np.linalg.cholesky(tensor) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you have to call the |
||
return L | ||
|
||
def qr( | ||
torch: Any, | ||
tensor: Tensor, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np
is thenumpy
module.numpy
does not havereduce_prod
, that's atensorflow
routine. This only passes the test because indecompositions_test.py
you are erroneously passing thetensorflow
module instead of thenumpy
module tonumpy.decompositions.cholesky
. pls fix this