changeset 21423:e169fe73b57e stable

svds.m: Special handling for case of sigma=0 (bug #46683). * svds.m: If ARPACK does not return the correct number of positive eigenvalues, then use the negative eigenvalues instead.
author Marco Caliari <marco.caliari@univr.it>
date Mon, 28 Dec 2015 08:40:05 -0800
parents 2e21387ce06b
children a3542f00c993 7bb71bf2f30f
files scripts/sparse/svds.m
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/sparse/svds.m	Thu Mar 03 09:27:04 2016 -0800
+++ b/scripts/sparse/svds.m	Mon Dec 28 08:40:05 2015 -0800
@@ -200,6 +200,14 @@
     ## less than or equal to zero to within some tolerance scaled by the
     ## norm since if we don't we might end up with too many singular
     ## values.
+    if (b_sigma == 0)
+      if (sum (s>0) < k)
+        ## It may happen that the number of positive s is less than k.
+        ## In this case, take -s (if s in an eigenvalue, so is -s),
+        ## flipped upside-down.
+        s = flipud (-s);
+      endif
+    endif
     tol = norma * opts.tol;
     ind = find (s > tol);
     if (length (ind) < k)