Mercurial > octave-nkf
diff scripts/general/postpad.m @ 18513:d28c4c4547ef gui-release
Allow postpad and prepad to expand singleton dimensions (bug #41633)
* postpad.m, prepad.m: Allow postpad and prepad to expand singleton
dimensions. Add %!tests. Remove %!errors that are no longer errors.
author | Mike Miller <mtmiller@ieee.org> |
---|---|
date | Fri, 21 Feb 2014 17:48:51 -0500 |
parents | d63878346099 |
children | 107ec5195a47 |
line wrap: on
line diff
--- a/scripts/general/postpad.m Fri Feb 21 08:05:37 2014 -0600 +++ b/scripts/general/postpad.m Fri Feb 21 17:48:51 2014 -0500 @@ -30,6 +30,9 @@ ## ## If the optional argument @var{dim} is given, operate along this ## dimension. +## +## If @var{dim} is larger than the dimensions of @var{x}, the result will +## have @var{dim} dimensions. ## @seealso{prepad, cat, resize} ## @end deftypefn @@ -56,8 +59,7 @@ ## Find the first non-singleton dimension. (dim = find (sz > 1, 1)) || (dim = 1); else - if (!(isscalar (dim) && dim == fix (dim)) - || !(1 <= dim && dim <= nd)) + if (!(isscalar (dim) && dim == fix (dim) && dim >= 1)) error ("postpad: DIM must be an integer and a valid dimension"); endif endif @@ -89,9 +91,10 @@ %!assert (postpad ([1,2], 4, 2), [1,2,2,2]) %!assert (postpad ([1;2], 4, 2), [1;2;2;2]) %!assert (postpad ([1,2], 2, 2, 1), [1,2;2,2]) +%!assert (postpad ([1;2], 2, 2, 3), reshape ([1;2;2;2], 2, 1, 2)) +%!assert (postpad ([1,2], 2, 2, 3), reshape ([1,2,2,2], 1, 2, 2)) %!error postpad () %!error postpad (1) %!error postpad (1,2,3,4,5) -%!error postpad ([1,2], 2, 2,3)