# HG changeset patch
# User Kai T. Ohlhus <k.ohlhus@gmail.com>
# Date 1543156763 -3600
#      Sun Nov 25 15:39:23 2018 +0100
# Node ID 1833060421db9a4282d8740554e3f6372697f02d
# Parent  84cd950f0f75cc29f56b0db03e2bd46722ff859d
Reenable query of optimization options (bugs #54952 and #55089).

* scripts/optimization/__all_opts__.m: Improve documentation of query mechanism.

* scripts/optimization/fminbnd.m, scripts/optimization/fminsearch.m,
scripts/optimization/fminunc.m, scripts/optimization/fsolve.m,
scripts/optimization/fzero.m, scripts/optimization/lsqnonneg.m,
scripts/optimization/pqpnonneg.m, default/scripts/optimization/qp.m:
Return a struct without double-check by optimset.  The sanity of the values is
always checked at Octave startup by the PKG_ADD invoked interplay of
"__all_opts__" and "optimset".

diff -r 84cd950f0f75 -r 1833060421db scripts/optimization/__all_opts__.m
--- a/scripts/optimization/__all_opts__.m	Sat Nov 24 20:52:59 2018 +0100
+++ b/scripts/optimization/__all_opts__.m	Sun Nov 25 15:39:23 2018 +0100
@@ -18,14 +18,16 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {} {@var{names} =} __all_opts__ (@dots{})
-## Undocumented internal function.
-## @end deftypefn
-
+## Internal function.
+##
 ## Query all options from all known optimization functions and return a
 ## list of possible values.
+## @end deftypefn
 
 function names = __all_opts__ (varargin)
 
+  ## This variable is filled by the auto-generated PKG_ADD script at
+  ## Octave startup.
   persistent saved_names = {};
 
   ## do not clear this function
@@ -39,7 +41,7 @@ function names = __all_opts__ (varargin)
   elseif (nargin == 0)
     names = saved_names;
   else
-    ## query all options from all known functions.  These will call optimset,
+    ## Query all options from all known functions.  These will call optimset,
     ## which will in turn call us, but we won't answer.
     recursive = true;
     names = saved_names;
diff -r 84cd950f0f75 -r 1833060421db scripts/optimization/fminbnd.m
--- a/scripts/optimization/fminbnd.m	Sat Nov 24 20:52:59 2018 +0100
+++ b/scripts/optimization/fminbnd.m	Sun Nov 25 15:39:23 2018 +0100
@@ -85,9 +85,9 @@ function [x, fval, info, output] = fminb
 
   ## Get default options if requested.
   if (nargin == 1 && ischar (fun) && strcmp (fun, "defaults"))
-    x = optimset ("Display", "notify", "FunValCheck", "off",
-                  "MaxFunEvals", 500, "MaxIter", 500,
-                  "OutputFcn", [], "TolX", 1e-4);
+    x = struct ("Display", "notify", "FunValCheck", "off",
+                "MaxFunEvals", 500, "MaxIter", 500,
+                "OutputFcn", [], "TolX", 1e-4);
     return;
   endif
 
diff -r 84cd950f0f75 -r 1833060421db scripts/optimization/fminsearch.m
--- a/scripts/optimization/fminsearch.m	Sat Nov 24 20:52:59 2018 +0100
+++ b/scripts/optimization/fminsearch.m	Sun Nov 25 15:39:23 2018 +0100
@@ -128,10 +128,10 @@ function [x, fval, exitflag, output] = f
 
   ## Get default options if requested.
   if (nargin == 1 && ischar (varargin{1}) && strcmp (varargin{1}, "defaults"))
-    x = optimset ("Display", "notify", "FunValCheck", "off",
-                  "MaxFunEvals", [], "MaxIter", [],
-                  "OutputFcn", [],
-                  "TolFun", 1e-4, "TolX", 1e-4);
+    x = struct ("Display", "notify", "FunValCheck", "off",
+                "MaxFunEvals", [], "MaxIter", [],
+                "OutputFcn", [],
+                "TolFun", 1e-4, "TolX", 1e-4);
     return;
   endif
 
diff -r 84cd950f0f75 -r 1833060421db scripts/optimization/fminunc.m
--- a/scripts/optimization/fminunc.m	Sat Nov 24 20:52:59 2018 +0100
+++ b/scripts/optimization/fminunc.m	Sun Nov 25 15:39:23 2018 +0100
@@ -98,11 +98,11 @@ function [x, fval, info, output, grad, h
 
   ## Get default options if requested.
   if (nargin == 1 && strcmp (fcn, "defaults"))
-    x = optimset ("MaxIter", 400, "MaxFunEvals", Inf,
-                  "GradObj", "off", "TolX", 1e-7, "TolFun", 1e-7,
-                  "OutputFcn", [], "FunValCheck", "off",
-                  "FinDiffType", "central",
-                  "TypicalX", [], "AutoScaling", "off");
+    x = struct ("MaxIter", 400, "MaxFunEvals", Inf,
+                "GradObj", "off", "TolX", 1e-7, "TolFun", 1e-7,
+                "OutputFcn", [], "FunValCheck", "off",
+                "FinDiffType", "central",
+                "TypicalX", [], "AutoScaling", "off");
     return;
   endif
 
diff -r 84cd950f0f75 -r 1833060421db scripts/optimization/fsolve.m
--- a/scripts/optimization/fsolve.m	Sat Nov 24 20:52:59 2018 +0100
+++ b/scripts/optimization/fsolve.m	Sun Nov 25 15:39:23 2018 +0100
@@ -172,11 +172,11 @@ function [x, fval, info, output, fjac] =
 
   ## Get default options if requested.
   if (nargin == 1 && ischar (fcn) && strcmp (fcn, "defaults"))
-    x = optimset ("AutoScaling", "off", "ComplexEqn", "off",
-                  "FunValCheck", "off", "FinDiffType", "forward",
-                  "Jacobian", "off",  "MaxFunEvals", [], "MaxIter", 400,
-                  "OutputFcn", [], "Updating", "off", "TolFun", 1e-6,
-                  "TolX", 1e-6, "TypicalX", []);
+    x = struct ("AutoScaling", "off", "ComplexEqn", "off",
+                "FunValCheck", "off", "FinDiffType", "forward",
+                "Jacobian", "off",  "MaxFunEvals", [], "MaxIter", 400,
+                "OutputFcn", [], "Updating", "off", "TolFun", 1e-6,
+                "TolX", 1e-6, "TypicalX", []);
     return;
   endif
 
diff -r 84cd950f0f75 -r 1833060421db scripts/optimization/fzero.m
--- a/scripts/optimization/fzero.m	Sat Nov 24 20:52:59 2018 +0100
+++ b/scripts/optimization/fzero.m	Sun Nov 25 15:39:23 2018 +0100
@@ -123,9 +123,9 @@ function [x, fval, info, output] = fzero
 
   ## Get default options if requested.
   if (nargin == 1 && ischar (fun) && strcmp (fun, "defaults"))
-    x = optimset ("Display", "notify", "FunValCheck", "off",
-                  "MaxFunEvals", Inf, "MaxIter", Inf,
-                  "OutputFcn", [], "TolX", eps);
+    x = struct ("Display", "notify", "FunValCheck", "off",
+                "MaxFunEvals", Inf, "MaxIter", Inf,
+                "OutputFcn", [], "TolX", eps);
     return;
   endif
 
diff -r 84cd950f0f75 -r 1833060421db scripts/optimization/lsqnonneg.m
--- a/scripts/optimization/lsqnonneg.m	Sat Nov 24 20:52:59 2018 +0100
+++ b/scripts/optimization/lsqnonneg.m	Sun Nov 25 15:39:23 2018 +0100
@@ -82,7 +82,7 @@ function [x, resnorm, residual, exitflag
 
   ## Special case: called to find default optimization options
   if (nargin == 1 && ischar (c) && strcmp (c, "defaults"))
-    x = optimset ("MaxIter", 1e5);
+    x = struct ("MaxIter", 1e5);
     return;
   endif
 
diff -r 84cd950f0f75 -r 1833060421db scripts/optimization/pqpnonneg.m
--- a/scripts/optimization/pqpnonneg.m	Sat Nov 24 20:52:59 2018 +0100
+++ b/scripts/optimization/pqpnonneg.m	Sun Nov 25 15:39:23 2018 +0100
@@ -84,7 +84,7 @@ function [x, minval, exitflag, output, l
 
   ## Special case: called to find default optimization options
   if (nargin == 1 && ischar (c) && strcmp (c, "defaults"))
-    x = optimset ("MaxIter", 1e5);
+    x = struct ("MaxIter", 1e5);
     return;
   endif
 
diff -r 84cd950f0f75 -r 1833060421db scripts/optimization/qp.m
--- a/scripts/optimization/qp.m	Sat Nov 24 20:52:59 2018 +0100
+++ b/scripts/optimization/qp.m	Sun Nov 25 15:39:23 2018 +0100
@@ -120,7 +120,7 @@
 function [x, obj, INFO, lambda] = qp (x0, H, varargin)
 
   if (nargin == 1 && ischar (x0) && strcmp (x0, "defaults"))
-    x = optimset ("MaxIter", 200);
+    x = struct ("MaxIter", 200);
     return;
   endif
 
