comparison scripts/general/repmat.m @ 19867:9fc020886ae9

maint: Clean up m-files to follow Octave coding conventions. Try to trim long lines to < 80 chars. Use '##' for single line comments. Use '(...)' around tests for if/elseif/switch/while. Abut cell indexing operator '{' next to variable. Abut array indexing operator '(' next to variable. Use space between negation operator '!' and following expression. Use two newlines between endfunction and start of %!test or %!demo code. Remove unnecessary parens grouping between short-circuit operators. Remove stray extra spaces (typos) between variables and assignment operators. Remove stray extra spaces from ends of lines.
author Rik <rik@octave.org>
date Mon, 23 Feb 2015 14:54:39 -0800
parents 4197fc428c7d
children 7503499a252b
comparison
equal deleted inserted replaced
19866:a1acca0c2216 19867:9fc020886ae9
66 m = m(:).'; 66 m = m(:).';
67 n = n(:).'; 67 n = n(:).';
68 endif 68 endif
69 else 69 else
70 if (nargin > 3) 70 if (nargin > 3)
71 # input check for m and varargin 71 ## input check for m and varargin
72 if (isscalar (m) && all (cellfun ("numel", varargin) == 1)) 72 if (isscalar (m) && all (cellfun ("numel", varargin) == 1))
73 m = [m varargin{:}]; 73 m = [m varargin{:}];
74 n = []; 74 n = [];
75 else 75 else
76 error ("repmat: all input arguments must be scalar"); 76 error ("repmat: all input arguments must be scalar");
135 endif 135 endif
136 136
137 endfunction 137 endfunction
138 138
139 139
140 # Tests for ML compatibility 140 ## Tests for ML compatibility
141 %!shared x 141 %!shared x
142 %! x = [1 2 3]; 142 %! x = [1 2 3];
143 %!assert (repmat (x, [3, 1]), repmat (x, 3, [])) 143 %!assert (repmat (x, [3, 1]), repmat (x, 3, []))
144 %!assert (repmat (x, [3, 1]), repmat (x, [], 3)) 144 %!assert (repmat (x, [3, 1]), repmat (x, [], 3))
145 %!assert (repmat (x, [1, 3]), repmat (x, [], [1, 3])) 145 %!assert (repmat (x, [1, 3]), repmat (x, [], [1, 3]))
150 %!assert (repmat (x, [1 1], 4), repmat (x, [1 3; 1 3], [1; 4])) 150 %!assert (repmat (x, [1 1], 4), repmat (x, [1 3; 1 3], [1; 4]))
151 %!assert (repmat (x, [1 1], 4), repmat (x, [1 3; 1 3], [1 2; 3 4])) 151 %!assert (repmat (x, [1 1], 4), repmat (x, [1 3; 1 3], [1 2; 3 4]))
152 %!assert (repmat (x, [1 1], 4), repmat (x, [1 1 4])); 152 %!assert (repmat (x, [1 1], 4), repmat (x, [1 1 4]));
153 %!assert (repmat (x, [1 1], 4), repmat (x, 1, [1 4])); 153 %!assert (repmat (x, [1 1], 4), repmat (x, 1, [1 4]));
154 154
155 # Test various methods of providing size parameters 155 ## Test various methods of providing size parameters
156 %!shared x 156 %!shared x
157 %! x = [1 2;3 4]; 157 %! x = [1 2;3 4];
158 %!assert (repmat (x, [1 1]), repmat (x, 1)) 158 %!assert (repmat (x, [1 1]), repmat (x, 1))
159 %!assert (repmat (x, [3 3]), repmat (x, 3)) 159 %!assert (repmat (x, [3 3]), repmat (x, 3))
160 %!assert (repmat (x, [1 1]), repmat (x, 1, 1)) 160 %!assert (repmat (x, [1 1]), repmat (x, 1, 1))
161 %!assert (repmat (x, [1 3]), repmat (x, 1, 3)) 161 %!assert (repmat (x, [1 3]), repmat (x, 1, 3))
162 %!assert (repmat (x, [3 1]), repmat (x, 3, 1)) 162 %!assert (repmat (x, [3 1]), repmat (x, 3, 1))
163 %!assert (repmat (x, [3 3]), repmat (x, 3, 3)) 163 %!assert (repmat (x, [3 3]), repmat (x, 3, 3))
164 %!assert (repmat (pi, [1,2,3,4]), repmat (pi, 1,2,3,4)) 164 %!assert (repmat (pi, [1,2,3,4]), repmat (pi, 1,2,3,4))
165 165
166 # Tests for numel==1 case: 166 ## Tests for numel==1 case:
167 %!shared x, r 167 %!shared x, r
168 %! x = [ 65 ]; 168 %! x = [ 65 ];
169 %! r = kron (ones (2,2), x); 169 %! r = kron (ones (2,2), x);
170 %!assert (r, repmat (x, [2 2])) 170 %!assert (r, repmat (x, [2 2]))
171 %!assert (char (r), repmat (char (x), [2 2])) 171 %!assert (char (r), repmat (char (x), [2 2]))
172 %!assert (int8 (r), repmat (int8 (x), [2 2])) 172 %!assert (int8 (r), repmat (int8 (x), [2 2]))
173 173
174 # Tests for ndims==2 case: 174 ## Tests for ndims==2 case:
175 %!shared x, r 175 %!shared x, r
176 %! x = [ 65 66 67 ]; 176 %! x = [ 65 66 67 ];
177 %! r = kron (ones (2,2), x); 177 %! r = kron (ones (2,2), x);
178 %!assert (r, repmat (x, [2 2])) 178 %!assert (r, repmat (x, [2 2]))
179 %!assert (char (r), repmat (char (x), [2 2])) 179 %!assert (char (r), repmat (char (x), [2 2]))
180 %!assert (int8 (r), repmat (int8 (x), [2 2])) 180 %!assert (int8 (r), repmat (int8 (x), [2 2]))
181 181
182 # Tests for dim>2 case: 182 ## Tests for dim>2 case:
183 %!shared x, r 183 %!shared x, r
184 %! x = [ 65 66 67 ]; 184 %! x = [ 65 66 67 ];
185 %! r = kron (ones (2,2), x); 185 %! r = kron (ones (2,2), x);
186 %! r(:,:,2) = r(:,:,1); 186 %! r(:,:,2) = r(:,:,1);
187 %!assert (r, repmat (x, [2 2 2])) 187 %!assert (r, repmat (x, [2 2 2]))
188 %!assert (char (r), repmat (char (x), [2 2 2])) 188 %!assert (char (r), repmat (char (x), [2 2 2]))
189 %!assert (int8 (r), repmat (int8 (x), [2 2 2])) 189 %!assert (int8 (r), repmat (int8 (x), [2 2 2]))
190 190
191 # Test that sparsity is kept 191 ## Test that sparsity is kept
192 %!assert (sparse (4,4), repmat (sparse (2,2),[2 2])) 192 %!assert (sparse (4,4), repmat (sparse (2,2),[2 2]))
193 193
194 %!assert (size (repmat (".", -1, 1)), [0, 1]) 194 %!assert (size (repmat (".", -1, 1)), [0, 1])
195 %!assert (size (repmat (".", 1, -1)), [1, 0]) 195 %!assert (size (repmat (".", 1, -1)), [1, 0])
196 196