From e472a831f8e8c9ce66357908d9d0a643cd9b96cb Mon Sep 17 00:00:00 2001 From: Conor McNamara Date: Thu, 10 Apr 2025 12:56:07 -0700 Subject: [PATCH] Add stopping condition for while loop The while loop in robust.py assumes that we've specified a high enough threshold to end. However, if the threshold is low enough, we will continue looping until we try to access an element that is beyond the size of s, creating an error. We have now added a stopping condition to that. --- pysyncon/robust.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pysyncon/robust.py b/pysyncon/robust.py index 2866465..8153852 100644 --- a/pysyncon/robust.py +++ b/pysyncon/robust.py @@ -102,9 +102,10 @@ def _sv_decomposition( if not threshold and not sv_count: raise ValueError("One of `threshold` or `sv_count` must be supplied.") u, s, v = np.linalg.svd(Y) + s_shape = s.shape[0] - 1 if threshold: idx = 0 - while s[idx] > threshold: + while s[idx] > threshold and idx < s_shape: idx += 1 else: idx = sv_count