Mercurial > pytave
comparison @pyobject/pyobject.m @ 426:8a26a4e649ba
pyobject.numel: delete, builtin numel is correct (fixes issue #88)
* @pyobject/pyobject.m: Delete numel, use the builtin numel to always
return 1 for Matlab compatibility.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Wed, 21 Feb 2018 16:12:39 -0800 |
parents | f833e29b2c12 |
children |
comparison
equal
deleted
inserted
replaced
425:14b134ffdc24 | 426:8a26a4e649ba |
---|---|
223 endfor | 223 endfor |
224 ## last is product of all remaining | 224 ## last is product of all remaining |
225 varargout{nargout-1} = prod (sz(nargout:end)); | 225 varargout{nargout-1} = prod (sz(nargout:end)); |
226 endfunction | 226 endfunction |
227 | 227 |
228 | |
229 function n = numel (x) | |
230 assert (nargin == 1) | |
231 sz = size (x); | |
232 n = prod (sz); | |
233 endfunction | |
234 | |
235 function n = ndims (x) | 228 function n = ndims (x) |
236 assert (nargin == 1) | 229 assert (nargin == 1) |
237 n = length (size (x)); | 230 n = length (size (x)); |
238 endfunction | 231 endfunction |
239 | 232 |
240 function r = end (x, index_pos, num_indices) | 233 function r = end (x, index_pos, num_indices) |
241 assert (nargin == 3) | 234 assert (nargin == 3) |
242 assert (isscalar (index_pos)) | 235 assert (isscalar (index_pos)) |
243 if (num_indices == 1) | 236 if (num_indices == 1) |
244 r = numel (x); | 237 r = prod (size (x)); |
245 else | 238 else |
246 r = size (x, index_pos); | 239 r = size (x, index_pos); |
247 endif | 240 endif |
248 endfunction | 241 endfunction |
249 | 242 |
288 %! [a b] = size (L); | 281 %! [a b] = size (L); |
289 %! assert ([a b], [1 3]) | 282 %! assert ([a b], [1 3]) |
290 %! [a b c] = size (L); | 283 %! [a b c] = size (L); |
291 %! assert ([a b c], [1 3 1]) | 284 %! assert ([a b c], [1 3 1]) |
292 | 285 |
293 %!assert (numel (pyeval ("[10, 20, 30]")), 3) | 286 %!assert (numel (pyeval ("[10, 20, 30]")), 1) |
294 | 287 |
295 %!test | 288 %!test |
296 %! L = pyeval ("[10, 20, 30]"); | 289 %! L = pyeval ("[10, 20, 30]"); |
297 %! assert (double (L{end}), 30) | 290 %! assert (double (L{end}), 30) |
298 %! assert (double (L{end-1}), 20) | 291 %! assert (double (L{end-1}), 20) |
319 %! [n m o] = size (a); | 312 %! [n m o] = size (a); |
320 %! assert ([n m o], [3 4 5]) | 313 %! assert ([n m o], [3 4 5]) |
321 %!test | 314 %!test |
322 %! [n m o p] = size (a); | 315 %! [n m o p] = size (a); |
323 %! assert ([n m o p], [3 4 5 1]) | 316 %! assert ([n m o p], [3 4 5 1]) |
324 %!assert (numel (a), 60) | 317 %!assert (numel (a), 1) |
325 %!assert (ndims (a), 3) | 318 %!assert (ndims (a), 3) |
326 %!shared | 319 %!shared |
327 | 320 |
328 ## Test conversion of scalar struct into a Python dict | 321 ## Test conversion of scalar struct into a Python dict |
329 %!shared s1 | 322 %!shared s1 |