annotate scripts/general/repmat.m @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents 7854d5752dd2
children 5d3faba0342e
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 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 2000-2022 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/>.
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
7 ##
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
8 ## This file is part of Octave.
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
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: 23220
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: 22323
diff changeset
13 ## (at your option) any later version.
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
14 ##
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
19 ##
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
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: 6987
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: 23220
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 ########################################################################
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
25
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
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 {} {} repmat (@var{A}, @var{m})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
28 ## @deftypefnx {} {} repmat (@var{A}, @var{m}, @var{n})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
29 ## @deftypefnx {} {} repmat (@var{A}, @var{m}, @var{n}, @var{p} @dots{})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
30 ## @deftypefnx {} {} repmat (@var{A}, [@var{m} @var{n}])
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
31 ## @deftypefnx {} {} repmat (@var{A}, [@var{m} @var{n} @var{p} @dots{}])
21521
02cbd95095cc doc: shorten repmat one-line description so it appears in "lookfor repeat".
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
32 ## Repeat matrix or N-D array.
02cbd95095cc doc: shorten repmat one-line description so it appears in "lookfor repeat".
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
33 ##
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
34 ## Form a block matrix of size @var{m} by @var{n}, with a copy of matrix
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
35 ## @var{A} as each element.
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
36 ##
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
37 ## If @var{n} is not specified, form an @var{m} by @var{m} block matrix. For
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
38 ## copying along more than two dimensions, specify the number of times to copy
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
39 ## across each dimension @var{m}, @var{n}, @var{p}, @dots{}, in a vector in the
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
40 ## second argument.
21521
02cbd95095cc doc: shorten repmat one-line description so it appears in "lookfor repeat".
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
41 ##
02cbd95095cc doc: shorten repmat one-line description so it appears in "lookfor repeat".
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
42 ## @seealso{bsxfun, kron, repelems}
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
43 ## @end deftypefn
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
44
19114
c53401edf4e3 make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents: 17744
diff changeset
45 function x = repmat (A, m, varargin)
3915
2f341412622f [project @ 2002-04-30 02:41:04 by jwe]
jwe
parents: 3914
diff changeset
46
19114
c53401edf4e3 make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents: 17744
diff changeset
47 if (nargin < 2)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5443
diff changeset
48 print_usage ();
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
49 endif
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
50
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4030
diff changeset
51 if (nargin == 3)
19114
c53401edf4e3 make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents: 17744
diff changeset
52 n = varargin{1};
15436
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
53 if (! isempty (m) && isempty (n))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
54 m = m(:).';
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
55 n = 1;
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
56 elseif (isempty (m) && ! isempty (n))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
57 m = n(:).';
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
58 n = 1;
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
59 elseif (isempty (m) && isempty (n))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
60 m = n = 1;
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
61 else
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
62 if (all (size (m) > 1))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
63 m = m(:,1);
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
64 if (numel (m) < 3)
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
65 n = n(end);
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
66 else
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
67 n = [];
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
68 endif
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
69 endif
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
70 if (all (size (n) > 1))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
71 n = n(:,1);
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
72 endif
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
73 m = m(:).';
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
74 n = n(:).';
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4030
diff changeset
75 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
76 else
19115
3132cd3d6625 repmat.m: Use Octave coding conventions in cset c53401edf4e3.
Rik <rik@octave.org>
parents: 19114
diff changeset
77 if (nargin > 3)
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
78 ## input check for m and varargin
19115
3132cd3d6625 repmat.m: Use Octave coding conventions in cset c53401edf4e3.
Rik <rik@octave.org>
parents: 19114
diff changeset
79 if (isscalar (m) && all (cellfun ("numel", varargin) == 1))
19114
c53401edf4e3 make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents: 17744
diff changeset
80 m = [m varargin{:}];
c53401edf4e3 make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents: 17744
diff changeset
81 n = [];
c53401edf4e3 make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents: 17744
diff changeset
82 else
19115
3132cd3d6625 repmat.m: Use Octave coding conventions in cset c53401edf4e3.
Rik <rik@octave.org>
parents: 19114
diff changeset
83 error ("repmat: all input arguments must be scalar");
21031
66a08c3cafe3 maint: Follow Octave coding conventions in m-files.
Rik <rik@octave.org>
parents: 20852
diff changeset
84 endif
19114
c53401edf4e3 make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents: 17744
diff changeset
85 elseif (isempty (m))
15436
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
86 m = n = 1;
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
87 elseif (isscalar (m))
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
88 n = m;
15436
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
89 elseif (ndims (m) > 2)
19115
3132cd3d6625 repmat.m: Use Octave coding conventions in cset c53401edf4e3.
Rik <rik@octave.org>
parents: 19114
diff changeset
90 error ("repmat: M has more than 2 dimensions");
15436
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
91 elseif (all (size (m) > 1))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
92 m = m(:,1).';
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
93 n = [];
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
94 else
15436
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
95 m = m(:).';
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
96 n = [];
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
97 endif
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
98 endif
15436
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
99 idx = [m, n];
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
100
8508
dee629f14bfa repmat.m: handle negative dimensions properly
John W. Eaton <jwe@octave.org>
parents: 8507
diff changeset
101 if (all (idx < 0))
19115
3132cd3d6625 repmat.m: Use Octave coding conventions in cset c53401edf4e3.
Rik <rik@octave.org>
parents: 19114
diff changeset
102 error ("repmat: invalid dimensions");
8508
dee629f14bfa repmat.m: handle negative dimensions properly
John W. Eaton <jwe@octave.org>
parents: 8507
diff changeset
103 else
dee629f14bfa repmat.m: handle negative dimensions properly
John W. Eaton <jwe@octave.org>
parents: 8507
diff changeset
104 idx = max (idx, 0);
dee629f14bfa repmat.m: handle negative dimensions properly
John W. Eaton <jwe@octave.org>
parents: 8507
diff changeset
105 endif
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
106
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
107 if (numel (A) == 1)
8390
49901b624316 optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
108 ## optimize the scalar fill case.
11318
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
109 if (any (idx == 0))
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
110 x = resize (A, idx);
11318
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
111 else
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
112 x(1:prod (idx)) = A;
11318
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
113 x = reshape (x, idx);
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
114 endif
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
115 elseif (ndims (A) == 2 && length (idx) < 3)
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
116 if (issparse (A))
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
117 x = kron (ones (idx), A);
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4030
diff changeset
118 else
8390
49901b624316 optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
119 ## indexing is now faster, so we use it rather than kron.
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
120 m = rows (A); n = columns (A);
8390
49901b624316 optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
121 p = idx(1); q = idx(2);
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
122 x = reshape (A, m, 1, n, 1);
8390
49901b624316 optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
123 x = x(:, ones (1, p), :, ones (1, q));
49901b624316 optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
124 x = reshape (x, m*p, n*q);
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4030
diff changeset
125 endif
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
126 else
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
127 aidx = size (A);
8970
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
128 ## ensure matching size
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
129 idx(end+1:length (aidx)) = 1;
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
130 aidx(end+1:length (idx)) = 1;
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
131 ## create subscript array
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
132 cidx = cell (2, length (aidx));
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8390
diff changeset
133 for i = 1:length (aidx)
8970
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
134 cidx{1,i} = ':';
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
135 cidx{2,i} = ones (1, idx (i));
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4030
diff changeset
136 endfor
8970
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
137 aaidx = aidx;
17336
b81b9d079515 Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents: 15436
diff changeset
138 ## add singleton dims
8970
b37a6c27c23f simplify repmat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
139 aaidx(2,:) = 1;
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
140 A = reshape (A, aaidx(:));
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11318
diff changeset
141 x = reshape (A (cidx{:}), idx .* aidx);
3914
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
142 endif
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
143
9eb96199e0f1 [project @ 2002-04-30 02:40:04 by jwe]
jwe
parents:
diff changeset
144 endfunction
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
145
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 17336
diff changeset
146
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
147 ## Tests for ML compatibility
15436
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
148 %!shared x
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
149 %! x = [1 2 3];
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
150 %!assert (repmat (x, [3, 1]), repmat (x, 3, []))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
151 %!assert (repmat (x, [3, 1]), repmat (x, [], 3))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
152 %!assert (repmat (x, [1, 3]), repmat (x, [], [1, 3]))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
153 %!assert (repmat (x, [1, 3]), repmat (x, [1, 3], []))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
154 %!assert (repmat (x, [1 3]), repmat (x, [1 3; 3 3]))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
155 %!assert (repmat (x, [1 1 2]), repmat (x, [1 1; 1 3; 2 1]))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
156 %!assert (repmat (x, [1 3; 1 3], [1; 3]), repmat (x, [1 1 3]))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
157 %!assert (repmat (x, [1 1], 4), repmat (x, [1 3; 1 3], [1; 4]))
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
158 %!assert (repmat (x, [1 1], 4), repmat (x, [1 3; 1 3], [1 2; 3 4]))
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21031
diff changeset
159 %!assert (repmat (x, [1 1], 4), repmat (x, [1 1 4]))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21031
diff changeset
160 %!assert (repmat (x, [1 1], 4), repmat (x, 1, [1 4]))
15436
32fd31378052 Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents: 15434
diff changeset
161
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
162 ## Test various methods of providing size parameters
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
163 %!shared x
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
164 %! x = [1 2;3 4];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
165 %!assert (repmat (x, [1 1]), repmat (x, 1))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
166 %!assert (repmat (x, [3 3]), repmat (x, 3))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
167 %!assert (repmat (x, [1 1]), repmat (x, 1, 1))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
168 %!assert (repmat (x, [1 3]), repmat (x, 1, 3))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
169 %!assert (repmat (x, [3 1]), repmat (x, 3, 1))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
170 %!assert (repmat (x, [3 3]), repmat (x, 3, 3))
19115
3132cd3d6625 repmat.m: Use Octave coding conventions in cset c53401edf4e3.
Rik <rik@octave.org>
parents: 19114
diff changeset
171 %!assert (repmat (pi, [1,2,3,4]), repmat (pi, 1,2,3,4))
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
172
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
173 ## Tests for numel==1 case:
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
174 %!shared x, r
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
175 %! x = [ 65 ];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
176 %! r = kron (ones (2,2), x);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
177 %!assert (r, repmat (x, [2 2]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
178 %!assert (char (r), repmat (char (x), [2 2]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
179 %!assert (int8 (r), repmat (int8 (x), [2 2]))
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
180
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
181 ## Tests for ndims==2 case:
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
182 %!shared x, r
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
183 %! x = [ 65 66 67 ];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
184 %! r = kron (ones (2,2), x);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
185 %!assert (r, repmat (x, [2 2]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
186 %!assert (char (r), repmat (char (x), [2 2]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
187 %!assert (int8 (r), repmat (int8 (x), [2 2]))
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
188
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
189 ## Tests for dim>2 case:
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
190 %!shared x, r
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
191 %! x = [ 65 66 67 ];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
192 %! r = kron (ones (2,2), x);
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
193 %! r(:,:,2) = r(:,:,1);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
194 %!assert (r, repmat (x, [2 2 2]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
195 %!assert (char (r), repmat (char (x), [2 2 2]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
196 %!assert (int8 (r), repmat (int8 (x), [2 2 2]))
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
197
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
198 ## Test that sparsity is kept
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
199 %!assert (sparse (4,4), repmat (sparse (2,2),[2 2]))
6987
deb175b6e4a1 [project @ 2007-10-09 18:39:15 by jwe]
jwe
parents: 6046
diff changeset
200
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
201 %!assert (size (repmat (".", -1, 1)), [0, 1])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
202 %!assert (size (repmat (".", 1, -1)), [1, 0])
8508
dee629f14bfa repmat.m: handle negative dimensions properly
John W. Eaton <jwe@octave.org>
parents: 8507
diff changeset
203
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
204 %!assert (size (repmat (1, [1, 0])), [1, 0])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
205 %!assert (size (repmat (1, [5, 0])), [5, 0])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
206 %!assert (size (repmat (1, [0, 1])), [0, 1])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
207 %!assert (size (repmat (1, [0, 5])), [0, 5])
11318
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
208
22215
a4551d2b5da5 repmat.m: add test for input with zero length dimensions.
Carnë Draug <carandraug@octave.org>
parents: 21521
diff changeset
209 %!assert (size (repmat (ones (0, 3), [2 3])), [0 9])
a4551d2b5da5 repmat.m: add test for input with zero length dimensions.
Carnë Draug <carandraug@octave.org>
parents: 21521
diff changeset
210 %!assert (size (repmat (ones (0, 0, 3), [2 3])), [0 0 3])
a4551d2b5da5 repmat.m: add test for input with zero length dimensions.
Carnë Draug <carandraug@octave.org>
parents: 21521
diff changeset
211
11318
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
212 %!shared x
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
213 %! x = struct ("a", [], "b", []);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
214 %!assert (size (repmat (x, [1, 0])), [1, 0])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
215 %!assert (size (repmat (x, [5, 0])), [5, 0])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
216 %!assert (size (repmat (x, [0, 1])), [0, 1])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
217 %!assert (size (repmat (x, [0, 5])), [0, 5])
11318
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
218
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
219 %!assert (size (repmat ({1}, [1, 0])), [1, 0])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
220 %!assert (size (repmat ({1}, [5, 0])), [5, 0])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
221 %!assert (size (repmat ({1}, [0, 1])), [0, 1])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14241
diff changeset
222 %!assert (size (repmat ({1}, [0, 5])), [0, 5])
11318
d7ea780b036f repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents: 10801
diff changeset
223
28930
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 27985
diff changeset
224 %!error size (repmat (".", -1, -1))