Mercurial > octave
changeset 30603:397d29f7135c
shift.m: Deprecate function in favor of circshift for Matlab compatibility.
* NEWS: Announce deprecation.
* scripts/deprecated/shift.m: Moved from scripts/general. Added warning about
deprecation emitted on first usage. Added note to docstring that function is
deprecated.
* scripts/deprecated/module.mk: Add shift.m to build system.
* scripts/general/module.mk: Remove shift.m from build system.
* matrix.txi: Remove shift() from manual.
* polyarea.m, __imread__.m, spinmap.m, findobj.m, treelayout.m, treeplot.m:
Replace instances of shift() with circshift().
* strjust.m: Replace instance of "shift (" with "shift(" because the code
is using indexing, not a function call.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 06 Jan 2022 17:48:06 -0800 |
parents | 916e13929773 |
children | a5e92ddf0a4d |
files | doc/interpreter/matrix.txi scripts/deprecated/module.mk scripts/deprecated/shift.m scripts/general/module.mk scripts/general/polyarea.m scripts/general/shift.m scripts/image/private/__imread__.m scripts/image/spinmap.m scripts/plot/util/findobj.m scripts/sparse/treelayout.m scripts/sparse/treeplot.m scripts/strings/strjust.m |
diffstat | 12 files changed, 127 insertions(+), 115 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/interpreter/matrix.txi Thu Jan 06 14:23:03 2022 -0800 +++ b/doc/interpreter/matrix.txi Thu Jan 06 17:48:06 2022 -0800 @@ -112,8 +112,6 @@ @DOCSTRING(circshift) -@DOCSTRING(shift) - @DOCSTRING(shiftdim) @DOCSTRING(sort)
--- a/scripts/deprecated/module.mk Thu Jan 06 14:23:03 2022 -0800 +++ b/scripts/deprecated/module.mk Thu Jan 06 17:48:06 2022 -0800 @@ -4,7 +4,8 @@ %reldir%/.oct-config \ %reldir%/disable_diagonal_matrix.m \ %reldir%/disable_permutation_matrix.m \ - %reldir%/disable_range.m + %reldir%/disable_range.m \ + %reldir%/shift.m %canon_reldir%dir = $(fcnfiledir)/deprecated
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/deprecated/shift.m Thu Jan 06 17:48:06 2022 -0800 @@ -0,0 +1,115 @@ +######################################################################## +## +## Copyright (C) 1995-2022 The Octave Project Developers +## +## See the file COPYRIGHT.md in the top-level directory of this +## distribution or <https://octave.org/copyright/>. +## +## This file is part of Octave. +## +## Octave is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <https://www.gnu.org/licenses/>. +## +######################################################################## + +## -*- texinfo -*- +## @deftypefn {} {} shift (@var{x}, @var{b}) +## @deftypefnx {} {} shift (@var{x}, @var{b}, @var{dim}) +## +## @code{shift} is deprecated and will be removed in Octave version 10. Use +## @code{circshift} instead. +## +## If @var{x} is a vector, perform a circular shift of length @var{b} of +## the elements of @var{x}. +## +## If @var{x} is a matrix, do the same for each column of @var{x}. +## +## If the optional @var{dim} argument is given, operate along this dimension. +## @seealso{circshift} +## @end deftypefn + +## FIXME: DEPRECATED: Remove in version 10. + +function y = shift (x, b, dim) + + persistent warned = false; + if (! warned) + warned = true; + warning ("Octave:deprecated-function", + "shift is deprecated and will be removed from a future version of Octave, please use circshift instead\n"); + endif + + if (nargin < 2) + print_usage (); + endif + + if (numel (x) < 1) + error ("shift: X must not be empty"); + elseif (! (isscalar (b) && b == fix (b))) + error ("shift: B must be an integer"); + endif + + nd = ndims (x); + sz = size (x); + + if (nargin == 3) + if (!(isscalar (dim) && dim == fix (dim)) + || !(1 <= dim && dim <= nd)) + error ("shift: DIM must be an integer and a valid dimension"); + endif + else + ## Find the first non-singleton dimension. + (dim = find (sz > 1, 1)) || (dim = 1); + endif + + d = sz(dim); + + idx = repmat ({':'}, nd, 1); + if (b > 0) + b = rem (b, d); + idx{dim} = [d-b+1:d, 1:d-b]; + elseif (b < 0) + b = rem (abs (b), d); + idx{dim} = [b+1:d, 1:b]; + endif + + y = x(idx{:}); + +endfunction + + +%!test +%! a = [1, 2, 3]; +%! b = [4, 5, 6]; +%! c = [7, 8, 9]; +%! +%! r = [a, b, c]; +%! m = [a; b; c]; +%! +%! assert (shift (r, 0), r); +%! assert (shift (r, 3), [c, a, b]); +%! assert (shift (r, -6), [c, a, b]); +%! assert (shift (r, -3), [b, c, a]); +%! assert (shift (m, 1), [c; a; b]); +%! assert (shift (m, -2), [c; a; b]); + +## Test input validation +%!error <Invalid call> shift () +%!error <Invalid call> shift (1) +%!error <X must not be empty> shift ([], 1) +%!error <B must be an integer> shift (ones (2), ones (2)) +%!error <B must be an integer> shift (ones (2), 1.5) +%!error <DIM must be an integer> shift (1, 1, 1.5) +%!error <DIM must be .* a valid dimension> shift (1, 1, 0) +%!error <DIM must be .* a valid dimension> shift (1, 1, 3)
--- a/scripts/general/module.mk Thu Jan 06 14:23:03 2022 -0800 +++ b/scripts/general/module.mk Thu Jan 06 17:48:06 2022 -0800 @@ -64,7 +64,6 @@ %reldir%/rng.m \ %reldir%/rot90.m \ %reldir%/rotdim.m \ - %reldir%/shift.m \ %reldir%/shiftdim.m \ %reldir%/sortrows.m \ %reldir%/sph2cart.m \
--- a/scripts/general/polyarea.m Thu Jan 06 14:23:03 2022 -0800 +++ b/scripts/general/polyarea.m Thu Jan 06 17:48:06 2022 -0800 @@ -55,9 +55,9 @@ endif if (nargin == 2) - a = abs (sum (x .* (shift (y, -1) - shift (y, 1)))) / 2; + a = abs (sum (x .* (circshift (y, -1) - circshift (y, 1)))) / 2; else - a = abs (sum (x .* (shift (y, -1, dim) - shift (y, 1, dim)), dim)) / 2; + a = abs (sum (x .* (circshift (y, -1, dim) - circshift (y, 1, dim)), dim)) / 2; endif endfunction
--- a/scripts/general/shift.m Thu Jan 06 14:23:03 2022 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -######################################################################## -## -## Copyright (C) 1995-2022 The Octave Project Developers -## -## See the file COPYRIGHT.md in the top-level directory of this -## distribution or <https://octave.org/copyright/>. -## -## This file is part of Octave. -## -## Octave is free software: you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation, either version 3 of the License, or -## (at your option) any later version. -## -## Octave is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, see -## <https://www.gnu.org/licenses/>. -## -######################################################################## - -## -*- texinfo -*- -## @deftypefn {} {} shift (@var{x}, @var{b}) -## @deftypefnx {} {} shift (@var{x}, @var{b}, @var{dim}) -## If @var{x} is a vector, perform a circular shift of length @var{b} of -## the elements of @var{x}. -## -## If @var{x} is a matrix, do the same for each column of @var{x}. -## -## If the optional @var{dim} argument is given, operate along this dimension. -## @end deftypefn - -function y = shift (x, b, dim) - - if (nargin < 2) - print_usage (); - endif - - if (numel (x) < 1) - error ("shift: X must not be empty"); - elseif (! (isscalar (b) && b == fix (b))) - error ("shift: B must be an integer"); - endif - - nd = ndims (x); - sz = size (x); - - if (nargin == 3) - if (!(isscalar (dim) && dim == fix (dim)) - || !(1 <= dim && dim <= nd)) - error ("shift: DIM must be an integer and a valid dimension"); - endif - else - ## Find the first non-singleton dimension. - (dim = find (sz > 1, 1)) || (dim = 1); - endif - - d = sz(dim); - - idx = repmat ({':'}, nd, 1); - if (b > 0) - b = rem (b, d); - idx{dim} = [d-b+1:d, 1:d-b]; - elseif (b < 0) - b = rem (abs (b), d); - idx{dim} = [b+1:d, 1:b]; - endif - - y = x(idx{:}); - -endfunction - - -%!test -%! a = [1, 2, 3]; -%! b = [4, 5, 6]; -%! c = [7, 8, 9]; -%! -%! r = [a, b, c]; -%! m = [a; b; c]; -%! -%! assert (shift (r, 0), r); -%! assert (shift (r, 3), [c, a, b]); -%! assert (shift (r, -6), [c, a, b]); -%! assert (shift (r, -3), [b, c, a]); -%! assert (shift (m, 1), [c; a; b]); -%! assert (shift (m, -2), [c; a; b]); - -## Test input validation -%!error <Invalid call> shift () -%!error <Invalid call> shift (1) -%!error <X must not be empty> shift ([], 1) -%!error <B must be an integer> shift (ones (2), ones (2)) -%!error <B must be an integer> shift (ones (2), 1.5) -%!error <DIM must be an integer> shift (1, 1, 1.5) -%!error <DIM must be .* a valid dimension> shift (1, 1, 0) -%!error <DIM must be .* a valid dimension> shift (1, 1, 3)
--- a/scripts/image/private/__imread__.m Thu Jan 06 14:23:03 2022 -0800 +++ b/scripts/image/private/__imread__.m Thu Jan 06 17:48:06 2022 -0800 @@ -61,7 +61,7 @@ if (sum (idx) > 1) error ("imread: Index or Frames may only be specified once"); endif - val = varargin{shift (idx, 1)}; + val = varargin{circshift (idx, 1)}; if (! is_valid_index_option (val) && ! strcmpi (val, "all")) error ("imread: %s must be a vector or the string 'all'", varargin{idx}); endif
--- a/scripts/image/spinmap.m Thu Jan 06 14:23:03 2022 -0800 +++ b/scripts/image/spinmap.m Thu Jan 06 17:48:06 2022 -0800 @@ -56,7 +56,7 @@ t0 = clock (); while (etime (clock (), t0) < t) - cmap = shift (cmap, inc, 1); + cmap = circshift (cmap, inc, 1); set (gcf (), "colormap", cmap); drawnow (); endwhile
--- a/scripts/plot/util/findobj.m Thu Jan 06 14:23:03 2022 -0800 +++ b/scripts/plot/util/findobj.m Thu Jan 06 17:48:06 2022 -0800 @@ -217,7 +217,7 @@ numpairs = np - 1; if (! isempty (logicaloperator)) - logicaloperator = shift (logicaloperator, 1); + logicaloperator = circshift (logicaloperator, 1); endif ## Load all objects which qualify for being searched.
--- a/scripts/sparse/treelayout.m Thu Jan 06 14:23:03 2022 -0800 +++ b/scripts/sparse/treelayout.m Thu Jan 06 17:48:06 2022 -0800 @@ -164,14 +164,14 @@ left_most += 1; x_coordinate_r(par_number) = left_most; max_ht = min (max_ht, level); - if (length (stk) > 1 && find ((shift (stk,1) - stk) == 0) > 1 + if (length (stk) > 1 && find ((circshift (stk,1) - stk) == 0) > 1 && stk(end,2) != stk(end-1,2)) ## Return to the nearest branching the position to return ## position is the position on the stack, where should be ## started further search (there are two nodes which has the ## same parent node). - position = (find ((shift (stk(:,2), 1) - stk(:,2)) == 0))(end) + 1; + position = (find ((circshift (stk(:,2), 1) - stk(:,2)) == 0))(end) + 1; par_number_vec = stk(position:end,2); ## The vector of removed nodes (the content of stack form
--- a/scripts/sparse/treeplot.m Thu Jan 06 14:23:03 2022 -0800 +++ b/scripts/sparse/treeplot.m Thu Jan 06 17:48:06 2022 -0800 @@ -127,13 +127,13 @@ left_most += 1; x_coordinate_r(par_number) = left_most; max_ht = min (max_ht, level); - if (length (stk) > 1 && find ((shift (stk,1) - stk) == 0) > 1 + if (length (stk) > 1 && find ((circshift (stk,1) - stk) == 0) > 1 && stk(end,2) != stk(end-1,2)) ## Return to the nearest branching the position to return ## position is the position on the stack, where should be ## started further search (there are two nodes which has the ## same parent node). - position = (find ((shift (stk(:,2),1) - stk(:,2)) == 0))(end) + 1; + position = (find ((circshift (stk(:,2),1) - stk(:,2)) == 0))(end) + 1; par_number_vec = stk(position:end,2); ## The vector of removed nodes (the content of stack form ## position to end).
--- a/scripts/strings/strjust.m Thu Jan 06 14:23:03 2022 -0800 +++ b/scripts/strings/strjust.m Thu Jan 06 17:48:06 2022 -0800 @@ -94,7 +94,7 @@ endif ## Adjust the column indices. - jdx += shift (idx); + jdx += shift(idx); ## Create a blank matrix and position the nonblank characters. y = repmat (" ", nr, nc);