changeset 26206:aaa23f9845dd

qp.m: Allow empty inequality constraints (bug #38483). * qp.m: Change input validation to only process inequality constraints if A_in is non-empty.
author Rik <rik@octave.org>
date Tue, 11 Dec 2018 16:00:43 -0800
parents cf037b842a9f
children b964092ad9f8
files scripts/optimization/qp.m
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/optimization/qp.m	Tue Dec 11 15:38:55 2018 -0800
+++ b/scripts/optimization/qp.m	Tue Dec 11 16:00:43 2018 -0800
@@ -264,14 +264,18 @@
   endif
 
   ## Validate inequality constraints.
-  if (nargs > 7)
+  if (nargs > 7 && isempty (A_in) && ! (isempty(A_lb) || isempty(A_ub)))
+    warning("qp: empty inequality constraint matrix but non-empty bound vectors");
+  endif
+
+  if (nargs > 7 && ! isempty (A_in))
     [dimA_in, n1] = size (A_in);
     if (n1 != n)
-      error ("qp: inequality constraint matrix has incorrect column dimension");
+      error ("qp: inequality constraint matrix has incorrect column dimension, expected %i", n1);
     else
       if (! isempty (A_lb))
         if (numel (A_lb) != dimA_in)
-          error ("qp: inequality constraint matrix and lower bound vector are inconsistent");
+          error ("qp: inequality constraint matrix and lower bound vector are inconsistent, %i != %i", dimA_in, numel (A_lb));
         elseif (isempty (A_ub))
           Ain = [Ain; A_in];
           bin = [bin; A_lb];
@@ -279,7 +283,7 @@
       endif
       if (! isempty (A_ub))
         if (numel (A_ub) != dimA_in)
-          error ("qp: inequality constraint matrix and upper bound vector are inconsistent");
+          error ("qp: inequality constraint matrix and upper bound vector are inconsistent, %i != %i", dimA_in, numel (A_ub));
         elseif (isempty (A_lb))
           Ain = [Ain; -A_in];
           bin = [bin; -A_ub];