annotate scripts/optimization/optimget.m @ 27918:b442ec6dda5c

use centralized file for copyright info for individual contributors * COPYRIGHT.md: New file. * In most other files, use "Copyright (C) YYYY-YYYY The Octave Project Developers" instead of tracking individual names in separate source files. The motivation is to reduce the effort required to update the notices each year. Until now, the Octave source files contained copyright notices that list individual contributors. I adopted these file-scope copyright notices because that is what everyone was doing 30 years ago in the days before distributed version control systems. But now, with many contributors and modern version control systems, having these file-scope copyright notices causes trouble when we update copyright years or refactor code. Over time, the file-scope copyright notices may become outdated as new contributions are made or code is moved from one file to another. Sometimes people contribute significant patches but do not add a line claiming copyright. Other times, people add a copyright notice for their contribution but then a later refactoring moves part or all of their contribution to another file and the notice is not moved with the code. As a practical matter, moving such notices is difficult -- determining what parts are due to a particular contributor requires a time-consuming search through the project history. Even managing the yearly update of copyright years is problematic. We have some contributors who are no longer living. Should we update the copyright dates for their contributions when we release new versions? Probably not, but we do still want to claim copyright for the project as a whole. To minimize the difficulty of maintaining the copyright notices, I would like to change Octave's sources to use what is described here: https://softwarefreedom.org/resources/2012/ManagingCopyrightInformation.html in the section "Maintaining centralized copyright notices": The centralized notice approach consolidates all copyright notices in a single location, usually a top-level file. This file should contain all of the copyright notices provided project contributors, unless the contribution was clearly insignificant. It may also credit -- without a copyright notice -- anyone who helped with the project but did not contribute code or other copyrighted material. This approach captures less information about contributions within individual files, recognizing that the DVCS is better equipped to record those details. As we mentioned before, it does have one disadvantage as compared to the file-scope approach: if a single file is separated from the distribution, the recipient won't see the contributors' copyright notices. But this can be easily remedied by including a single copyright notice in each file's header, pointing to the top-level file: Copyright YYYY-YYYY The Octave Project Developers See the COPYRIGHT file at the top-level directory of this distribution or at https://octave.org/COPYRIGHT.html. followed by the usual GPL copyright statement. For more background, see the discussion here: https://lists.gnu.org/archive/html/octave-maintainers/2020-01/msg00009.html Most files in the following directories have been skipped intentinally in this changeset: doc libgui/qterminal liboctave/external m4
author John W. Eaton <jwe@octave.org>
date Mon, 06 Jan 2020 15:38:17 -0500
parents 00f796120a6d
children 1891570abac8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1 ## Copyright (C) 2008-2019 The Octave Project Developers
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
2 ##
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ## or <https://octave.org/COPYRIGHT.html/>.
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
5 ##
8304
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
6 ##
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
7 ## This file is part of Octave.
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
8 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
9 ## Octave is free software: you can redistribute it and/or modify it
8304
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
10 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
11 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
12 ## (at your option) any later version.
8304
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
13 ##
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
14 ## Octave is distributed in the hope that it will be useful, but
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## GNU General Public License for more details.
8304
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
18 ##
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
19 ## You should have received a copy of the GNU General Public License
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
20 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
21 ## <https://www.gnu.org/licenses/>.
8304
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
22
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
23 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19833
diff changeset
24 ## @deftypefn {} {} optimget (@var{options}, @var{parname})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19833
diff changeset
25 ## @deftypefnx {} {} optimget (@var{options}, @var{parname}, @var{default})
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
26 ## Return the specific option @var{parname} from the optimization options
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
27 ## structure @var{options} created by @code{optimset}.
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
28 ##
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
29 ## If @var{parname} is not defined then return @var{default} if supplied,
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
30 ## otherwise return an empty matrix.
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
31 ## @seealso{optimset}
8304
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
32 ## @end deftypefn
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
33
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
34 function retval = optimget (options, parname, default)
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
35
8647
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8304
diff changeset
36 if (nargin < 2 || nargin > 4 || ! isstruct (options) || ! ischar (parname))
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8304
diff changeset
37 print_usage ();
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8304
diff changeset
38 endif
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8304
diff changeset
39
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
40 ## Expand partial-length names into full names
8647
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8304
diff changeset
41 opts = __all_opts__ ();
17405
3f0ed69d21c6 Replace unnecessary instances of strncmp with strcmp.
Rik <rik@octave.org>
parents: 17338
diff changeset
42 idx = strncmpi (opts, parname, length (parname));
16674
bc79ac595a05 allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
43 nmatch = sum (idx);
8647
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8304
diff changeset
44
16674
bc79ac595a05 allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
45 if (nmatch == 1)
8647
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8304
diff changeset
46 parname = opts{idx};
16674
bc79ac595a05 allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
47 elseif (nmatch == 0)
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
48 warning ("optimget: unrecognized option: %s", parname);
8647
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8304
diff changeset
49 else
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
50 fmt = sprintf ("optimget: ambiguous option: %%s (%s%%s)",
16674
bc79ac595a05 allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
51 repmat ("%s, ", 1, nmatch-1));
bc79ac595a05 allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
52 warning (fmt, parname, opts{idx});
8647
06f5dd901f30 implement registering of optimization options
Jaroslav Hajek <highegg@gmail.com>
parents: 8304
diff changeset
53 endif
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
54
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
55 if (isfield (options, parname) && ! isempty (options.(parname)))
8304
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
56 retval = options.(parname);
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
57 elseif (nargin > 2)
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
58 retval = default;
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
59 else
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
60 retval = [];
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
61 endif
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
62
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
63 endfunction
eeaee297c0da modify optimset & implement optimget
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
64
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 16674
diff changeset
65
16674
bc79ac595a05 allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
66 %!shared opts
bc79ac595a05 allow abbreviations for optimset and optimget (bug #38999)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
67 %! opts = optimset ("tolx", 0.1, "maxit", 100);
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
68 %!assert (optimget (opts, "TolX"), 0.1)
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
69 %!assert (optimget (opts, "maxit"), 100)
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
70 %!assert (optimget (opts, "MaxITer"), 100)
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
71 %!assert (optimget (opts, "TolFun"), [])
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
72 %!assert (optimget (opts, "TolFun", 1e-3), 1e-3)
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 16674
diff changeset
73
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
74 ## Test input validation
18602
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
75 %!error optimget ()
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
76 %!error optimget (1)
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
77 %!error optimget (1,2,3,4,5)
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
78 %!error optimget (1, "name")
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
79 %!error optimget (struct (), 2)
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
80 %!warning <unrecognized option: foobar> (optimget (opts, "foobar"));
8d4d78285c8e Overhaul optimset/optimget functions for Matlab compatibility (bug #41915).
Rik <rik@octave.org>
parents: 17744
diff changeset
81 %!warning <ambiguous option: Max> (optimget (opts, "Max"));