Skip to content
This repository was archived by the owner on Nov 7, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tensornetwork/backends/numpy/decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def svd_decomposition(
right_dims = tensor.shape[split_axis:]

tensor = np.reshape(tensor, [numpy.prod(left_dims), numpy.prod(right_dims)])
u, s, vh = np.linalg.svd(tensor)
u, s, vh = np.linalg.svd(tensor, full_matrices=False)

if max_singular_values is None:
max_singular_values = np.size(s)
Expand Down
12 changes: 12 additions & 0 deletions tensornetwork/backends/numpy/decompositions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ def test_max_singular_values(self):
self.assertEqual(vh.shape, (7, 10))
self.assertAllClose(trun, np.arange(2, -1, -1))

def test_max_singular_values_larger_than_bond_dimension(self):
random_matrix = np.random.rand(10, 6)
unitary1, _, unitary2 = np.linalg.svd(random_matrix, full_matrices=False)
singular_values = np.array(range(6))
val = unitary1.dot(np.diag(singular_values).dot(unitary2.T))
u, s, vh, _ = decompositions.svd_decomposition(
np, val, 1, max_singular_values=30)
self.assertEqual(u.shape, (10, 6))
self.assertEqual(s.shape, (6,))
self.assertEqual(vh.shape, (6, 6))


def test_max_truncation_error(self):
random_matrix = np.random.rand(10, 10)
unitary1, _, unitary2 = np.linalg.svd(random_matrix)
Expand Down