changeset 25037:1c077d652c57 stable

Add new warning ID and message when lu is called with sparse input incorrectly (bug #53390). * lu.cc (Flu): Add new warning_with_id call with ID "Octave:lu:sparse_input" if lu is called with sparse input and less than 4 output arguments. * warning_ids.m: Document new warning ID "Octave:lu:sparse_input".
author Rik <rik@octave.org>
date Wed, 28 Mar 2018 10:55:17 -0700
parents fa2f8ffd088e
children 63f17bf9932a
files libinterp/corefcn/lu.cc scripts/help/warning_ids.m
diffstat 2 files changed, 23 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/lu.cc	Wed Mar 28 08:57:11 2018 -0700
+++ b/libinterp/corefcn/lu.cc	Wed Mar 28 10:55:17 2018 -0700
@@ -196,10 +196,14 @@
 
           if (nargout < 4)
             {
+              warning_with_id ("Octave:lu:sparse_input",
+                               "lu: function may fail when called with less than 4 output arguments and a sparse input");
+
               ColumnVector Qinit (nc);
               for (octave_idx_type i = 0; i < nc; i++)
                 Qinit(i) = i;
-              octave::math::sparse_lu<SparseMatrix> fact (m, Qinit, thres, false, true);
+              octave::math::sparse_lu<SparseMatrix> fact (m, Qinit, thres,
+                                                          false, true);
 
               if (nargout < 2)
                 retval(0) = fact.Y ();
@@ -261,6 +265,9 @@
 
           if (nargout < 4)
             {
+              warning_with_id ("Octave:lu:sparse_input",
+                               "lu: function may fail when called with less than 4 output arguments and a sparse input");
+
               ColumnVector Qinit (nc);
               for (octave_idx_type i = 0; i < nc; i++)
                 Qinit(i) = i;
@@ -299,7 +306,8 @@
           else
             {
               retval.resize (scale ? 5 : 4);
-              octave::math::sparse_lu<SparseComplexMatrix> fact (m, thres, scale);
+              octave::math::sparse_lu<SparseComplexMatrix> fact (m, thres,
+                                                                 scale);
 
               retval(0) = octave_value (fact.L (),
                                         MatrixType (MatrixType::Lower));
@@ -530,14 +538,12 @@
 %! assert (u, single ([5, 6; 0, 4/5]), sqrt (eps ("single")));
 %! assert (p(:,:), single ([0, 0, 1; 1, 0, 0; 0 1 0]), sqrt (eps ("single")));
 
-%!error lu ()
-%!error <can not define pivoting threshold> lu ([1, 2; 3, 4], 2)
-
 %!testif HAVE_UMFPACK
 %! Bi = [1 2 3 4 5 2 3 6 7 8 4 5 7 8 9];
 %! Bj = [1 3 4 5 6 7 8 9 11 12 13 14 15 16 17];
 %! Bv = [1 1 1 1 1 1 -1 1 1 1 1 -1 1 -1 1];
 %! B = sparse (Bi, Bj, Bv);
+%! warning ("off", "Octave:lu:sparse_input", "local");
 %! [L, U] = lu (B);
 %! assert (L*U, B);
 %! [L, U, P] = lu(B);
@@ -545,6 +551,11 @@
 %! [L, U, P, Q] = lu (B);
 %! assert (P'*L*U*Q', B);
 
+%!error lu ()
+%!warning <function may fail>
+%! [l,u] = lu (sparse (magic (3)));
+%!error <can not define pivoting threshold> lu ([1, 2; 3, 4], 2)
+
 */
 
 static
--- a/scripts/help/warning_ids.m	Wed Mar 28 08:57:11 2018 -0700
+++ b/scripts/help/warning_ids.m	Wed Mar 28 10:55:17 2018 -0700
@@ -214,6 +214,13 @@
 ## @item Octave:logical-conversion
 ## By default, the @code{Octave:logical-conversion} warning is enabled.
 ##
+## @item Octave:lu:sparse_input
+## If the @code{Octave:lu:sparse_input} warning is enabled, Octave
+## will warn when the lu function is called with a sparse input and less than
+## four output arguments.  In this case, sparsity-preserving column
+## permutations are not performed and the result may be inaccurate.
+## By default, the @code{Octave:lu:sparse_input} warning is enabled.
+##
 ## @item Octave:missing-glyph
 ## By default, the @code{Octave:missing-glyph} warning is enabled.
 ##