annotate scripts/general/postpad.m @ 27923:bd51beb6205e

update formatting of copyright notices * Use <https://octave.org/copyright/> instead of <https://octave.org/COPYRIGHT.html/>. * For consistency with other comments in the Octave sources, use C++-style comments for copyright blocks in C and C++ files. * Use delimiters above and below copyright blocks that are appropriate for the language used in the file. * Eliminate extra spacing inside copyright blocks. * lex.ll (looks_like_copyright): Also allow newlines and carriage returns before the word "Copyright". * scripts/mk-doc.pl (gethelp): Also skip empty comment lines. * bp-table.cc, type.m: Adjust tests.
author John W. Eaton <jwe@octave.org>
date Wed, 08 Jan 2020 11:59:41 -0500
parents 1891570abac8
children bdad8ca48700
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
27919
1891570abac8 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27918
diff changeset
3 ## Copyright (C) 1994-2020 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
7 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
8 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23573
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
11 ## 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: 23573
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
13 ## (at your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22489
diff changeset
18 ## GNU General Public License for more details.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
19 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
21 ## 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: 23573
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1337
diff changeset
25
3458
d25bc039237b [project @ 2000-01-19 09:36:14 by jwe]
jwe
parents: 3428
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
27 ## @deftypefn {} {} postpad (@var{x}, @var{l})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
28 ## @deftypefnx {} {} postpad (@var{x}, @var{l}, @var{c})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
29 ## @deftypefnx {} {} postpad (@var{x}, @var{l}, @var{c}, @var{dim})
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 11539
diff changeset
30 ## Append the scalar value @var{c} to the vector @var{x} until it is of length
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 11539
diff changeset
31 ## @var{l}. If @var{c} is not given, a value of 0 is used.
11539
6bac61388876 Add undocumented postpad function to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
32 ##
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
33 ## If @code{length (@var{x}) > @var{l}}, elements from the end of @var{x} are
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
34 ## removed until a vector of length @var{l} is obtained.
11539
6bac61388876 Add undocumented postpad function to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
35 ##
6bac61388876 Add undocumented postpad function to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
36 ## If @var{x} is a matrix, elements are appended or removed from each row.
6bac61388876 Add undocumented postpad function to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
37 ##
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
38 ## If the optional argument @var{dim} is given, operate along this dimension.
18513
d28c4c4547ef Allow postpad and prepad to expand singleton dimensions (bug #41633)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
39 ##
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
40 ## If @var{dim} is larger than the dimensions of @var{x}, the result will have
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
41 ## @var{dim} dimensions.
11539
6bac61388876 Add undocumented postpad function to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
42 ## @seealso{prepad, cat, resize}
3458
d25bc039237b [project @ 2000-01-19 09:36:14 by jwe]
jwe
parents: 3428
diff changeset
43 ## @end deftypefn
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3202
diff changeset
44
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3202
diff changeset
45 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3202
diff changeset
46 ## Created: June 1994
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 561
diff changeset
47
4862
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
48 function y = postpad (x, l, c, dim)
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
49
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
50 if (nargin < 2 || nargin > 4)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5459
diff changeset
51 print_usage ();
4862
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
52 endif
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
53
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
54 if (nargin < 3 || isempty (c))
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
55 c = 0;
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
56 else
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
57 if (! isscalar (c))
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
58 error ("postpad: third argument must be empty or a scalar");
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
59 endif
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
60 endif
561
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
61
4862
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
62 nd = ndims (x);
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
63 sz = size (x);
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
64 if (nargin < 4)
12674
9493880928c8 Use common idiom in m-files for finding first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 12639
diff changeset
65 ## Find the first non-singleton dimension.
9493880928c8 Use common idiom in m-files for finding first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 12639
diff changeset
66 (dim = find (sz > 1, 1)) || (dim = 1);
4862
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
67 else
18513
d28c4c4547ef Allow postpad and prepad to expand singleton dimensions (bug #41633)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
68 if (!(isscalar (dim) && dim == fix (dim) && dim >= 1))
10690
35adf2a71f3f Use common code block to find first non-singleton dimension.
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
69 error ("postpad: DIM must be an integer and a valid dimension");
4862
a0997c4d1d54 [project @ 2004-04-15 21:14:43 by jwe]
jwe
parents: 4030
diff changeset
70 endif
561
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
71 endif
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
72
5459
ff40c78cebf0 [project @ 2005-09-20 19:18:34 by jwe]
jwe
parents: 5307
diff changeset
73 if (! isscalar (l) || l < 0)
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
74 error ("postpad: second argument must be a positive scaler");
561
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
75 endif
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
76
5459
ff40c78cebf0 [project @ 2005-09-20 19:18:34 by jwe]
jwe
parents: 5307
diff changeset
77 if (dim > nd)
ff40c78cebf0 [project @ 2005-09-20 19:18:34 by jwe]
jwe
parents: 5307
diff changeset
78 sz(nd+1:dim) = 1;
ff40c78cebf0 [project @ 2005-09-20 19:18:34 by jwe]
jwe
parents: 5307
diff changeset
79 endif
ff40c78cebf0 [project @ 2005-09-20 19:18:34 by jwe]
jwe
parents: 5307
diff changeset
80
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
81 d = sz(dim);
5459
ff40c78cebf0 [project @ 2005-09-20 19:18:34 by jwe]
jwe
parents: 5307
diff changeset
82
22210
30eefd9ddb48 prepad, postpad: do nothing wen input is already of the right size.
Carnë Draug <carandraug@octave.org>
parents: 20852
diff changeset
83 if (d == l)
30eefd9ddb48 prepad, postpad: do nothing wen input is already of the right size.
Carnë Draug <carandraug@octave.org>
parents: 20852
diff changeset
84 ## This optimization makes sense because the function is used to match
30eefd9ddb48 prepad, postpad: do nothing wen input is already of the right size.
Carnë Draug <carandraug@octave.org>
parents: 20852
diff changeset
85 ## the length between two vectors not knowing a priori is larger, and
30eefd9ddb48 prepad, postpad: do nothing wen input is already of the right size.
Carnë Draug <carandraug@octave.org>
parents: 20852
diff changeset
86 ## allow for:
30eefd9ddb48 prepad, postpad: do nothing wen input is already of the right size.
Carnë Draug <carandraug@octave.org>
parents: 20852
diff changeset
87 ## ml = max (numel (v1), numel (v2));
30eefd9ddb48 prepad, postpad: do nothing wen input is already of the right size.
Carnë Draug <carandraug@octave.org>
parents: 20852
diff changeset
88 ## v1 = postpad (v1, ml);
30eefd9ddb48 prepad, postpad: do nothing wen input is already of the right size.
Carnë Draug <carandraug@octave.org>
parents: 20852
diff changeset
89 ## v2 = postpad (v2, ml);
30eefd9ddb48 prepad, postpad: do nothing wen input is already of the right size.
Carnë Draug <carandraug@octave.org>
parents: 20852
diff changeset
90 y = x;
30eefd9ddb48 prepad, postpad: do nothing wen input is already of the right size.
Carnë Draug <carandraug@octave.org>
parents: 20852
diff changeset
91 elseif (d >= l)
12676
2783fa95cab7 Use common code idiom for creating cell array for indexing ND-arrays
Rik <octave@nomad.inbox5.com>
parents: 12674
diff changeset
92 idx = repmat ({':'}, nd, 1);
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7017
diff changeset
93 idx{dim} = 1:l;
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7017
diff changeset
94 y = x(idx{:});
561
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
95 else
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
96 sz(dim) = l - d;
16304
c8e1b0213e34 pkg.m: Fix str-to-num warnings (bug #37785)
Rik <rik@octave.org>
parents: 14363
diff changeset
97 y = cat (dim, x, c(ones (sz)));
561
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
98 endif
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
99
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
100 endfunction
12795
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12676
diff changeset
101
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12676
diff changeset
102
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
103 %!assert (postpad ([1,2], 4), [1,2,0,0])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
104 %!assert (postpad ([1;2], 4), [1;2;0;0])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
105 %!assert (postpad ([1,2], 4, 2), [1,2,2,2])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
106 %!assert (postpad ([1;2], 4, 2), [1;2;2;2])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
107 %!assert (postpad ([1,2], 2, 2, 1), [1,2;2,2])
18513
d28c4c4547ef Allow postpad and prepad to expand singleton dimensions (bug #41633)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
108 %!assert (postpad ([1;2], 2, 2, 3), reshape ([1;2;2;2], 2, 1, 2))
d28c4c4547ef Allow postpad and prepad to expand singleton dimensions (bug #41633)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
109 %!assert (postpad ([1,2], 2, 2, 3), reshape ([1,2,2,2], 1, 2, 2))
12795
9e7ebbaf69ff codesprint: new tests for files in scripts/general directory
John W. Eaton <jwe@octave.org>
parents: 12676
diff changeset
110
22210
30eefd9ddb48 prepad, postpad: do nothing wen input is already of the right size.
Carnë Draug <carandraug@octave.org>
parents: 20852
diff changeset
111 %!assert (postpad ([1 2], 2), [1 2])
30eefd9ddb48 prepad, postpad: do nothing wen input is already of the right size.
Carnë Draug <carandraug@octave.org>
parents: 20852
diff changeset
112 %!assert (postpad ([1; 2], 2), [1; 2])
30eefd9ddb48 prepad, postpad: do nothing wen input is already of the right size.
Carnë Draug <carandraug@octave.org>
parents: 20852
diff changeset
113 %!assert (postpad ([1; 2], 2, 3, 2), [1 3; 2 3])
30eefd9ddb48 prepad, postpad: do nothing wen input is already of the right size.
Carnë Draug <carandraug@octave.org>
parents: 20852
diff changeset
114
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22323
diff changeset
115 %! ## Test with string concatenation
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
116 %!assert <*44162> (postpad ("Octave", 16, "x"), "Octavexxxxxxxxxx")
19654
107ec5195a47 prepad.m: Fix str-to-num warnings (bug #44162)
Mike Miller <mtmiller@ieee.org>
parents: 18513
diff changeset
117 %!assert (postpad ("Octave", 4), "Octa")
107ec5195a47 prepad.m: Fix str-to-num warnings (bug #44162)
Mike Miller <mtmiller@ieee.org>
parents: 18513
diff changeset
118
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
119 %!error postpad ()
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
120 %!error postpad (1)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
121 %!error postpad (1,2,3,4,5)