Mercurial > hg > octave-nkf
diff scripts/optimization/optimget.m @ 16674:bc79ac595a05
allow abbreviations for optimset and optimget (bug #38999)
* optimset.m, optimget.m: Handle abbreviated keys and warn for
ambiguous abbreviations. New tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 17 May 2013 12:56:44 -0400 |
parents | 72c96de7a403 |
children | 1c89599167a6 |
line wrap: on
line diff
--- a/scripts/optimization/optimget.m +++ b/scripts/optimization/optimget.m @@ -33,12 +33,18 @@ endif opts = __all_opts__ (); - idx = lookup (tolower (opts), tolower (parname), "m"); + idx = strncmpi (opts, parname, numel (parname)); + + nmatch = sum (idx); - if (idx) + if (nmatch == 1) parname = opts{idx}; + elseif (nmatch == 0) + warning ("unrecognized option: %s", parname); else - warning ("unrecognized option: %s", parname); + fmt = sprintf ("ambiguous option: %%s (%s%%s)", + repmat ("%s, ", 1, nmatch-1)); + warning (fmt, parname, opts{idx}); endif if (isfield (options, parname)) retval = options.(parname); @@ -50,3 +56,12 @@ endfunction +%!error optimget () + +%!shared opts +%! opts = optimset ("tolx", 0.1, "maxit", 100); +%!assert (optimget (opts, "TolX"), 0.1); +%!assert (optimget (opts, "maxit"), 100); +%!assert (optimget (opts, "MaxITer"), 100); +%!warning (optimget (opts, "Max")); +%!warning (optimget (opts, "foobar"));