Skip to content

Commit

Permalink
Fix symmetric svd decomp (#944)
Browse files Browse the repository at this point in the history
* modify decompositions.svd to allow truncating all singular values

* modify decompositions.svd to allow truncating all singular values

* updated test_max_truncation_error

* remove unusedvariable
  • Loading branch information
mganahl committed Oct 5, 2021
1 parent d87ee43 commit e5bf7e2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
8 changes: 1 addition & 7 deletions tensornetwork/backends/symmetric/decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ def svd(
#sort singular values
inds = np.argsort(extended_flat_singvals, kind='stable')
discarded_inds = np.zeros(0, dtype=SIZE_T)
if inds.shape[0] > 0:
maxind = inds[-1]
else:
maxind = 0
if max_truncation_error is not None:
if relative and (len(singvals) > 0):
max_truncation_error = max_truncation_error * np.max(
Expand All @@ -114,9 +110,7 @@ def svd(

if len(inds) == 0:
#special case of truncation to 0 dimension;
warnings.warn("svd_decomposition truncated to 0 dimensions. "
"Adjusting to `max_singular_values = 1`")
inds = np.asarray([maxind])
warnings.warn("svd_decomposition truncated to 0 dimensions.")

if extended_singvals.shape[1] > 0:
#pylint: disable=no-member
Expand Down
5 changes: 3 additions & 2 deletions tensornetwork/backends/symmetric/decompositions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ def test_max_singular_values(dtype, R, R1, num_charges):

@pytest.mark.parametrize("dtype", np_dtypes)
@pytest.mark.parametrize("num_charges", [1, 2, 3])
def test_max_truncation_error(dtype, num_charges):
np.random.seed(10)
@pytest.mark.parametrize("seed", np.arange(20))
def test_max_truncation_error(dtype, num_charges, seed):
np.random.seed(seed)
R = 2
D = 30
charges = [
Expand Down

0 comments on commit e5bf7e2

Please sign in to comment.