Mercurial > hg > octave-nkf
diff scripts/signal/ifftshift.m @ 20447:abbe33bf0c74 stable
fftshift.m, ifftshift.m: Restore support for N-dimensional arrays (bug #45207)
* fftshift.m, ifftshift.m: Improve input argument validation instead of
calling ismatrix to restore support for N-dimensional arrays. Rephrase
error messages. Add %!tests for N-dimensional inputs and %!error input
validation tests.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Thu, 28 May 2015 22:16:24 -0400 |
parents | f1d0f506ee78 |
children |
line wrap: on
line diff
--- a/scripts/signal/ifftshift.m +++ b/scripts/signal/ifftshift.m @@ -34,15 +34,17 @@ function retval = ifftshift (x, dim) - retval = 0; - if (nargin != 1 && nargin != 2) print_usage (); endif + if (! (isnumeric (x) || islogical (x) || ischar (x))) + error ("ifftshift: X must be a vector or matrix"); + endif + if (nargin == 2) - if (! isscalar (dim)) - error ("ifftshift: dimension must be an integer scalar"); + if (! (isscalar (dim) && dim > 0 && dim == fix (dim))) + error ("ifftshift: dimension DIM must be a positive integer"); endif nd = ndims (x); sz = size (x); @@ -55,7 +57,7 @@ xl = length (x); xx = floor (xl/2); retval = x([xx+1:xl, 1:xx]); - elseif (ismatrix (x)) + else nd = ndims (x); sz = size (x); sz2 = floor (sz ./ 2); @@ -64,8 +66,6 @@ idx{i} = [sz2(i)+1:sz(i), 1:sz2(i)]; endfor retval = x(idx{:}); - else - error ("ifftshift: expecting vector or matrix argument"); endif endif @@ -117,3 +117,24 @@ %! assert (y, [[2 3 0 1];[4 6 0 2];[7 10 1 4];[9 13 1 5]]); %! assert (ifftshift (y,2), x); +%!test +%! x = "efgabcd"; +%! y = ifftshift (x); +%! assert (y, "abcdefg"); +%! assert (ifftshift (y), "defgabc"); + +## Test N-dimensional input (bug #45207) +%!test +%! x = [0:3]; +%! x = x + x' + reshape (x, [1 1 4]); +%! y1 = [4 5 2 3; 5 6 3 4; 2 3 0 1; 3 4 1 2]; +%! y = ifftshift (x); +%! assert (y, reshape ([y1 + 2, y1 + 3, y1, y1 + 1], [4 4 4])); +%! assert (ifftshift (y), x); + +%% Test input validation +%!error ifftshift () +%!error ifftshift (1, 2, 3) +%!error ifftshift (0:3, -1) +%!error ifftshift (0:3, 0:3) +