Mercurial > hg > octave-nkf
annotate scripts/general/repmat.m @ 19830:884e0c55d92c
Fix complex compare operation for issorted (bug #44071).
* Array-C.cc (nan_ascending_compare, nan_descending_compare): Fix typo where
comparison was made between x and x rather than between x and y.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 26 Jan 2015 15:32:49 -0800 |
parents | 3132cd3d6625 |
children | 4197fc428c7d |
rev | line source |
---|---|
19306
c53401edf4e3
make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents:
17744
diff
changeset
|
1 ## Copyright (C) 2014 Markus Bergholz |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17338
diff
changeset
|
2 ## Copyright (C) 2000-2013 Paul Kienzle |
8390
49901b624316
optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
3 ## Copyright (C) 2008 Jaroslav Hajek |
3914 | 4 ## |
5 ## This file is part of Octave. | |
6 ## | |
7 ## Octave is free software; you can redistribute it and/or modify it | |
8 ## under the terms of the GNU General Public License as published by | |
7016 | 9 ## the Free Software Foundation; either version 3 of the License, or (at |
10 ## your option) any later version. | |
3914 | 11 ## |
12 ## Octave is distributed in the hope that it will be useful, but | |
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 ## General Public License for more details. | |
16 ## | |
17 ## You should have received a copy of the GNU General Public License | |
7016 | 18 ## along with Octave; see the file COPYING. If not, see |
19 ## <http://www.gnu.org/licenses/>. | |
3914 | 20 |
21 ## -*- texinfo -*- | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
22 ## @deftypefn {Function File} {} repmat (@var{A}, @var{m}) |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
23 ## @deftypefnx {Function File} {} repmat (@var{A}, @var{m}, @var{n}) |
19306
c53401edf4e3
make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents:
17744
diff
changeset
|
24 ## @deftypefnx {Function File} {} repmat (@var{A}, @var{m}, @var{n}, @var{p} @dots{}) |
3914 | 25 ## @deftypefnx {Function File} {} repmat (@var{A}, [@var{m} @var{n}]) |
9041
853f96e8008f
Cleanup documentation file matrix.texi
Rik <rdrider0-list@yahoo.com>
parents:
8970
diff
changeset
|
26 ## @deftypefnx {Function File} {} repmat (@var{A}, [@var{m} @var{n} @var{p} @dots{}]) |
3914 | 27 ## Form a block matrix of size @var{m} by @var{n}, with a copy of matrix |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
28 ## @var{A} as each element. If @var{n} is not specified, form an |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
29 ## @var{m} by @var{m} block matrix. For copying along more than two |
14241
a52925666288
repmat.m: Fix incorrect docstring regarding higher dimensions
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
30 ## dimensions, specify the number of times to copy across each dimension |
a52925666288
repmat.m: Fix incorrect docstring regarding higher dimensions
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
31 ## @var{m}, @var{n}, @var{p}, @dots{}, in a vector in the second argument. |
10801
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
32 ## @seealso{repelems} |
3914 | 33 ## @end deftypefn |
34 | |
35 ## Author: Paul Kienzle <pkienzle@kienzle.powernet.co.uk> | |
36 ## Created: July 2000 | |
37 | |
19306
c53401edf4e3
make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents:
17744
diff
changeset
|
38 function x = repmat (A, m, varargin) |
3915 | 39 |
19306
c53401edf4e3
make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents:
17744
diff
changeset
|
40 if (nargin < 2) |
6046 | 41 print_usage (); |
3914 | 42 endif |
43 | |
4844 | 44 if (nargin == 3) |
19306
c53401edf4e3
make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents:
17744
diff
changeset
|
45 n = varargin{1}; |
15436
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
46 if (! isempty (m) && isempty (n)) |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
47 m = m(:).'; |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
48 n = 1; |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
49 elseif (isempty (m) && ! isempty (n)) |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
50 m = n(:).'; |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
51 n = 1; |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
52 elseif (isempty (m) && isempty (n)) |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
53 m = n = 1; |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
54 else |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
55 if (all (size (m) > 1)) |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
56 m = m(:,1); |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
57 if (numel (m) < 3) |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
58 n = n(end); |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
59 else |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
60 n = []; |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
61 endif |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
62 endif |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
63 if (all (size (n) > 1)) |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
64 n = n(:,1); |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
65 endif |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
66 m = m(:).'; |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
67 n = n(:).'; |
4844 | 68 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
69 else |
19307
3132cd3d6625
repmat.m: Use Octave coding conventions in cset c53401edf4e3.
Rik <rik@octave.org>
parents:
19306
diff
changeset
|
70 if (nargin > 3) |
19306
c53401edf4e3
make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents:
17744
diff
changeset
|
71 # input check for m and varargin |
19307
3132cd3d6625
repmat.m: Use Octave coding conventions in cset c53401edf4e3.
Rik <rik@octave.org>
parents:
19306
diff
changeset
|
72 if (isscalar (m) && all (cellfun ("numel", varargin) == 1)) |
19306
c53401edf4e3
make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents:
17744
diff
changeset
|
73 m = [m varargin{:}]; |
c53401edf4e3
make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents:
17744
diff
changeset
|
74 n = []; |
c53401edf4e3
make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents:
17744
diff
changeset
|
75 else |
19307
3132cd3d6625
repmat.m: Use Octave coding conventions in cset c53401edf4e3.
Rik <rik@octave.org>
parents:
19306
diff
changeset
|
76 error ("repmat: all input arguments must be scalar"); |
19306
c53401edf4e3
make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents:
17744
diff
changeset
|
77 end |
c53401edf4e3
make repmat do accept more than 3 arguments (bug #38391)
Markus Bergholz <markuman+octave@gmail.com>
parents:
17744
diff
changeset
|
78 elseif (isempty (m)) |
15436
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
79 m = n = 1; |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
80 elseif (isscalar (m)) |
3914 | 81 n = m; |
15436
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
82 elseif (ndims (m) > 2) |
19307
3132cd3d6625
repmat.m: Use Octave coding conventions in cset c53401edf4e3.
Rik <rik@octave.org>
parents:
19306
diff
changeset
|
83 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
|
84 elseif (all (size (m) > 1)) |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
85 m = m(:,1).'; |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
86 n = []; |
3914 | 87 else |
15436
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
88 m = m(:).'; |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
89 n = []; |
3914 | 90 endif |
91 endif | |
15436
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
92 idx = [m, n]; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
93 |
8508
dee629f14bfa
repmat.m: handle negative dimensions properly
John W. Eaton <jwe@octave.org>
parents:
8507
diff
changeset
|
94 if (all (idx < 0)) |
19307
3132cd3d6625
repmat.m: Use Octave coding conventions in cset c53401edf4e3.
Rik <rik@octave.org>
parents:
19306
diff
changeset
|
95 error ("repmat: invalid dimensions"); |
8508
dee629f14bfa
repmat.m: handle negative dimensions properly
John W. Eaton <jwe@octave.org>
parents:
8507
diff
changeset
|
96 else |
dee629f14bfa
repmat.m: handle negative dimensions properly
John W. Eaton <jwe@octave.org>
parents:
8507
diff
changeset
|
97 idx = max (idx, 0); |
dee629f14bfa
repmat.m: handle negative dimensions properly
John W. Eaton <jwe@octave.org>
parents:
8507
diff
changeset
|
98 endif |
3914 | 99 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11318
diff
changeset
|
100 if (numel (A) == 1) |
8390
49901b624316
optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
101 ## 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 x = kron (ones (idx), A); |
4844 | 111 else |
8390
49901b624316
optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
112 ## 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
|
113 m = rows (A); n = columns (A); |
8390
49901b624316
optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
114 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
|
115 x = reshape (A, m, 1, n, 1); |
8390
49901b624316
optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
116 x = x(:, ones (1, p), :, ones (1, q)); |
49901b624316
optimize repmat for scalar & matrix case
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
117 x = reshape (x, m*p, n*q); |
4844 | 118 endif |
3914 | 119 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
|
120 aidx = size (A); |
8970 | 121 ## ensure matching size |
122 idx(end+1:length (aidx)) = 1; | |
123 aidx(end+1:length (idx)) = 1; | |
124 ## create subscript array | |
125 cidx = cell (2, length (aidx)); | |
8507 | 126 for i = 1:length (aidx) |
8970 | 127 cidx{1,i} = ':'; |
128 cidx{2,i} = ones (1, idx (i)); | |
4844 | 129 endfor |
8970 | 130 aaidx = aidx; |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
15436
diff
changeset
|
131 ## add singleton dims |
8970 | 132 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
|
133 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
|
134 x = reshape (A (cidx{:}), idx .* aidx); |
3914 | 135 endif |
136 | |
137 endfunction | |
6987 | 138 |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
139 |
15436
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
140 # Tests for ML compatibility |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
141 %!shared x |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
142 %! x = [1 2 3]; |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
143 %!assert (repmat (x, [3, 1]), repmat (x, 3, [])) |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
144 %!assert (repmat (x, [3, 1]), repmat (x, [], 3)) |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
145 %!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
|
146 %!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
|
147 %!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
|
148 %!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
|
149 %!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
|
150 %!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
|
151 %!assert (repmat (x, [1 1], 4), repmat (x, [1 3; 1 3], [1 2; 3 4])) |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
152 %!assert (repmat (x, [1 1], 4), repmat (x, [1 1 4])); |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
153 %!assert (repmat (x, [1 1], 4), repmat (x, 1, [1 4])); |
32fd31378052
Additional changes to repmat.m (e1f59fd57756).
Ben Abbott <bpabbott@mac.com>
parents:
15434
diff
changeset
|
154 |
6987 | 155 # Test various methods of providing size parameters |
156 %!shared x | |
157 %! 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
|
158 %!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
|
159 %!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
|
160 %!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
|
161 %!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
|
162 %!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
|
163 %!assert (repmat (x, [3 3]), repmat (x, 3, 3)) |
19307
3132cd3d6625
repmat.m: Use Octave coding conventions in cset c53401edf4e3.
Rik <rik@octave.org>
parents:
19306
diff
changeset
|
164 %!assert (repmat (pi, [1,2,3,4]), repmat (pi, 1,2,3,4)) |
6987 | 165 |
166 # Tests for numel==1 case: | |
167 %!shared x, r | |
168 %! x = [ 65 ]; | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14241
diff
changeset
|
169 %! 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
|
170 %!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
|
171 %!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
|
172 %!assert (int8 (r), repmat (int8 (x), [2 2])) |
6987 | 173 |
174 # Tests for ndims==2 case: | |
175 %!shared x, r | |
176 %! 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
|
177 %! 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
|
178 %!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
|
179 %!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
|
180 %!assert (int8 (r), repmat (int8 (x), [2 2])) |
6987 | 181 |
182 # Tests for dim>2 case: | |
183 %!shared x, r | |
184 %! 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
|
185 %! r = kron (ones (2,2), x); |
6987 | 186 %! 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
|
187 %!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
|
188 %!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
|
189 %!assert (int8 (r), repmat (int8 (x), [2 2 2])) |
6987 | 190 |
191 # 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
|
192 %!assert (sparse (4,4), repmat (sparse (2,2),[2 2])) |
6987 | 193 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14241
diff
changeset
|
194 %!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
|
195 %!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
|
196 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14241
diff
changeset
|
197 %!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
|
198 %!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
|
199 %!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
|
200 %!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
|
201 |
d7ea780b036f
repmat: handle special case of replicating scalar using index vector containing zeros
John W. Eaton <jwe@octave.org>
parents:
10801
diff
changeset
|
202 %!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
|
203 %! 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
|
204 %!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
|
205 %!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
|
206 %!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
|
207 %!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
|
208 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14241
diff
changeset
|
209 %!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
|
210 %!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
|
211 %!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
|
212 %!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
|
213 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14241
diff
changeset
|
214 %!error (size (repmat (".", -1, -1))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14241
diff
changeset
|
215 |