changeset 26734:75d79c39ac92

Replace '-0' in sigma matrix from svd() with '+0' (bug #55710). * liboctave/numeric/svd.cc (svd (const T& a, svd::Type type, svd::Driver driver): After calling LAPACK routine to calculate svd, check for zeros in sigma matrix and replace them with '+0'. * libinterp/corefcn/svd.cc (Fsvd): Add BIST test for bug #55710.
author Rik <rik@octave.org>
date Thu, 14 Feb 2019 16:38:00 -0800
parents f034b29320ad
children f85d491d2322
files libinterp/corefcn/svd.cc liboctave/numeric/svd.cc
diffstat 2 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/svd.cc	Fri Feb 08 18:07:33 2019 +0100
+++ b/libinterp/corefcn/svd.cc	Thu Feb 14 16:38:00 2019 -0800
@@ -372,6 +372,8 @@
 %! [~,~,v] = svd ([1, 1, 1], "econ");
 %! assert (size (v), [3 1]);
 
+%!assert <*55710> (1 / svd (-0), Inf)
+
 %!error svd ()
 %!error svd ([1, 2; 4, 5], 2, 3)
 */
--- a/liboctave/numeric/svd.cc	Fri Feb 08 18:07:33 2019 +0100
+++ b/liboctave/numeric/svd.cc	Thu Feb 14 16:38:00 2019 -0800
@@ -385,6 +385,13 @@
       else
         (*current_liboctave_error_handler) ("svd: unknown driver");
 
+      // LAPACK can return -0 which is a small problem (bug #55710).
+      for (octave_idx_type i = 0; i < sigma.diag_length (); i++)
+        {
+          if (! sigma.dgxelem (i))
+            sigma.dgxelem (i) = DM_P (0);
+        }
+
       if (! (jobv == 'N' || jobv == 'O'))
         right_sm = right_sm.hermitian ();
     }