Skip to content

Commit 25defd3

Browse files
MathiasMNilsenKriFos1
authored andcommitted
Update truncSVD
1 parent 51c9cf0 commit 25defd3

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

pipt/misc_tools/analysis_tools.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,11 +1528,12 @@ def truncSVD(matrix, r=None, energy=None, full_matrices=False):
15281528
# If not specified rank, energy must be given
15291529
if r is None:
15301530
if energy is not None:
1531-
# If energy is less than 100 we truncate the SVD matrices
1531+
# Energy is given as fraction
15321532
if energy < 1:
1533-
r = np.sum((np.cumsum(S) / sum(S)) <= energy)
1533+
r = np.searchsorted(np.cumsum(S)/np.sum(S), energy)
1534+
# Energy is given as a percentage
15341535
else:
1535-
r = np.sum((np.cumsum(S) / sum(S)) <= energy/100)
1536+
r = np.searchsorted(np.cumsum(S)/np.sum(S), energy/100)
15361537
else:
15371538
raise ValueError("Either rank 'r' or 'energy' must be specified for truncSVD.")
15381539

0 commit comments

Comments
 (0)