From a93b47c67db254b4a34cd84b6466faa1e681deab Mon Sep 17 00:00:00 2001 From: Jonas Thies <16190001+jthies@users.noreply.github.com> Date: Tue, 16 Aug 2022 07:51:37 +0200 Subject: [PATCH] avoid infinite loop in repeated_mgs and dgks orthogonalization --- jadapy/orthogonalization.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/jadapy/orthogonalization.py b/jadapy/orthogonalization.py index dd4780c..187862f 100644 --- a/jadapy/orthogonalization.py +++ b/jadapy/orthogonalization.py @@ -26,10 +26,13 @@ def DGKS(V, w, W=None, M=None, MV=None, MW=None): nrm = norm(w, M) eta = 1 / sqrt(2) - while nrm < eta * prev_nrm: + it = 0 + maxit = 3 + while nrm < eta * prev_nrm and it < maxit: gram_schmidt(V, w, W, M, MV, MW) prev_nrm = nrm nrm = norm(w, M) + it += 1 return nrm @@ -61,11 +64,15 @@ def repeated_mgs(V, w, W=None, M=None, MV=None, MW=None): modified_gs(V, w, W, M, MV, MW) nrm = norm(w, M) + it = 0 + maxit = 3 + eta = 1 / sqrt(2) - while nrm < eta * prev_nrm: + while nrm < eta * prev_nrm and it < maxit: modified_gs(V, w, W, M, MV, MW) prev_nrm = nrm nrm = norm(w, M) + it += 1 return nrm