diff liboctave/numeric/svd.cc @ 26731: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 00f796120a6d
children b442ec6dda5c
line wrap: on
line diff
--- 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 ();
     }