changeset 32248:3df98fee838b

doc: Expand optimset, optimget docstrings on parameter matching (bug #64525) * optimget.m,optimset.m: Add docstrings explanations of pattern matching, standard parameter lists, warnings on unknown parameters, and errors on ambiguities. Describe effects of adding unknown parameters and limitations of functions querying ambiguously named parameters. Add warning about actions that could cause unpredictable behavior. Adjust docstring variable names to be consistent betweeen both functions.
author Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
date Wed, 09 Aug 2023 16:06:57 -0400
parents 0b551b864e4c
children 120134e43537
files scripts/optimization/optimget.m scripts/optimization/optimset.m
diffstat 2 files changed, 46 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/optimization/optimget.m	Wed Aug 09 20:44:44 2023 +0200
+++ b/scripts/optimization/optimget.m	Wed Aug 09 16:06:57 2023 -0400
@@ -24,13 +24,27 @@
 ########################################################################
 
 ## -*- texinfo -*-
-## @deftypefn  {} {@var{optval} =} optimget (@var{options}, @var{optname})
-## @deftypefnx {} {@var{optval} =} optimget (@var{options}, @var{optname}, @var{default})
-## Return the specific option @var{optname} from the optimization options
-## structure @var{options} created by @code{optimset}.
+## @deftypefn  {} {@var{val} =} optimget (@var{options}, @var{par})
+## @deftypefnx {} {@var{val} =} optimget (@var{options}, @var{par}, @var{default})
+## Return the value of the specific parameter @var{par} from the optimization
+## options structure @var{options} created by @code{optimset}.
+##
+## If @var{par} is not defined then return the @var{default} value if
+## supplied, otherwise return an empty matrix.
 ##
-## If @var{optname} is not defined then return @var{default} if supplied,
-## otherwise return an empty matrix.
+## If @var{par} does not exactly match the name of a standard parameter,
+## @code{optimget} will attempt to expand the name to match a standard
+## parameter and will return that parameter's value if a match is found.
+## @code{optimget} produces an error if it finds multiple ambiguous matches.
+## If no standard parameter matches are found a warning is issued.  See
+## @code{optimset} for information about the standard options list.
+##
+## Note that any non-standard field names in @var{options} are ignored when
+## matching option names, and @var{par} will always be expanded
+## to match a standard option even if an exact non-standard match exists.  The
+## value of a non-standard parameter that is ambigious with one or more
+## standard parameters cannot be returned by @code{optimget} and can only be
+## accessed using @code{getfield} or dot notation for structs.
 ## @seealso{optimset}
 ## @end deftypefn
 
--- a/scripts/optimization/optimset.m	Wed Aug 09 20:44:44 2023 +0200
+++ b/scripts/optimization/optimset.m	Wed Aug 09 16:06:57 2023 -0400
@@ -44,7 +44,14 @@
 ## are updated from either the @var{par}/@var{val} list or from the options
 ## structure @var{new}.
 ##
-## Valid parameters are:
+## If @var{par} does not exactly match the name of a standard parameter,
+## @code{optimset} will attempt to expand the name to match a standard
+## parameter and will set the value of that parameter if a match is found.
+## @code{optimset} produces an error if it finds multiple ambiguous matches.
+## If no standard parameter matches are found a warning is issued and the
+## non-standard parameter is created.
+##
+## Standard list of valid parameters:
 ##
 ## @table @asis
 ## @item AutoScaling
@@ -116,6 +123,24 @@
 ##
 ## @item Updating
 ## @end table
+##
+## This list can be extended by the user or other loaded Octave packages. An
+## updated valid parameters list can be queried using the no-argument form of
+## @code{optimset}.
+##
+## Note 1:  Any non-standard field names in @var{old} are ignored when
+## matching parameter names, and @var{par} will always match to a standard
+## parameter even if an exact non-standard match exists.  The value of a
+## non-standard parameter that is ambigious with one or more standard
+## parameters cannot be set by @code{optimset} and can only be set using
+## @code{setfield} or dot notation for structs.
+##
+## Note 2:  The optimization options structure is primarily intended for
+## manipulation of known parameters by @code{optimset} and @code{optimget}.
+## Unpredictable behavior on future calls to @code{optimset} or
+## @code{optimget} can result from creating non-standard or ambiguous
+## parameters or from loading/unloading packages that change the known
+## parameter list after creation of an optimization options structure.
 ## @seealso{optimget}
 ## @end deftypefn