annotate scripts/general/circshift.m @ 33623:4517f929c59d bytecode-interpreter tip

maint: Merge default to bytecode-interpreter
author Arun Giridhar <arungiridhar@gmail.com>
date Fri, 24 May 2024 16:22:41 -0400
parents 2e484f9f1f18
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
3 ## Copyright (C) 2004-2024 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26600
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
7 ##
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
8 ## This file is part of Octave.
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
14 ##
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
19 ##
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6671
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
25
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20749
diff changeset
27 ## @deftypefn {} {@var{y} =} circshift (@var{x}, @var{n})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20749
diff changeset
28 ## @deftypefnx {} {@var{y} =} circshift (@var{x}, @var{n}, @var{dim})
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
29 ## Circularly shift the values of the array @var{x}.
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
30 ##
20749
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
31 ## @var{n} must be a vector of integers no longer than the number of dimensions
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
32 ## in @var{x}. The values of @var{n} can be either positive or negative, which
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
33 ## determines the direction in which the values of @var{x} are shifted. If an
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
34 ## element of @var{n} is zero, then the corresponding dimension of @var{x} will
26155
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
35 ## not be shifted. If @var{n} is a scalar and no @var{dim} is specified then
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
36 ## the shift is applied to the first non-singular dimension.
20749
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
37 ##
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
38 ## If a scalar @var{dim} is given then operate along the specified dimension.
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
39 ## In this case @var{n} must be a scalar as well.
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
40 ##
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
41 ## Examples:
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
42 ##
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
43 ## @example
26155
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
44 ## x = [1, 2, 3;
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
45 ## 4, 5, 6;
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
46 ## 7, 8, 9];
26577
ae1542fb58ba documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
47 ## ## positive shift on rows (1st non-singular dim)
ae1542fb58ba documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
48 ## circshift (x, 1)
26600
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
49 ## @result{}
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
50 ## 7 8 9
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
51 ## 1 2 3
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
52 ## 4 5 6
26577
ae1542fb58ba documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
53 ## ## negative shift on rows (1st non-singular dim)
ae1542fb58ba documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
54 ## circshift (x, -2)
26600
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
55 ## @result{}
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
56 ## 7 8 9
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
57 ## 1 2 3
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
58 ## 4 5 6
26577
ae1542fb58ba documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
59 ## ## no shift of rows, shift columns by 1 (2nd dimension)
ae1542fb58ba documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
60 ## circshift (x, [0,1])
26600
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
61 ## @result{}
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
62 ## 3 1 2
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
63 ## 6 4 5
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
64 ## 9 7 8
26577
ae1542fb58ba documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
65 ## ## shift columns (2nd dimension)
ae1542fb58ba documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
66 ## circshift (x, 1, 2)
26600
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
67 ## @result{}
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
68 ## 3 1 2
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
69 ## 6 4 5
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
70 ## 9 7 8
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
71 ## @end example
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
72 ## @seealso{permute, ipermute, shiftdim}
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
73 ## @end deftypefn
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
74
20749
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
75 function y = circshift (x, n, dim)
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
76
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27923
diff changeset
77 if (nargin < 2)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
78 print_usage ();
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
79 endif
13277
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
80
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
81 if (isempty (x))
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
82 y = x;
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
83 return;
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
84 endif
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
85
26155
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
86 nd = ndims (x);
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
87 sz = size (x);
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
88
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
89 if (nargin == 2)
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
90 if (isscalar (n))
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
91 ## Find the first non-singleton dimension.
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
92 (dim = find (sz > 1, 1)) || (dim = 1);
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
93 n = [zeros(1, dim-1), n];
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
94 endif
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
95 elseif (nargin == 3)
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
96 if ( ! isscalar (n))
20749
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
97 error ("circshift: N must be a scalar when DIM is also specified");
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
98 endif
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
99 n = [zeros(1, dim-1), n];
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
100 endif
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
101
13277
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
102 if (! isvector (n) || length (n) > nd)
20749
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
103 error ("circshift: N must be a vector, no longer than the number of dimensions in X");
13277
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
104 elseif (any (n != fix (n)))
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
105 error ("circshift: all values of N must be integers");
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
106 endif
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
107
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
108 idx = repmat ({':'}, 1, nd);
26268
6dd232798997 maint: Remove useless ';' from end of for, if, while, etc. statements.
Rik <rik@octave.org>
parents: 26155
diff changeset
109 for i = 1:length (n)
13277
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
110 b = n(i);
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
111 d = sz(i);
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
112 if (b > 0)
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
113 b = rem (b, d);
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
114 idx{i} = [d-b+1:d, 1:d-b];
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
115 elseif (b < 0)
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
116 b = rem (abs (b), d);
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
117 idx{i} = [b+1:d, 1:b];
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
118 endif
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
119 endfor
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
120
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
121 y = x(idx{:});
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
122
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
123 endfunction
7614
52f90c7adac6 Avoid infinite loop in circshift for infinite matrices
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
124
13277
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
125
7614
52f90c7adac6 Avoid infinite loop in circshift for infinite matrices
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
126 %!shared x
52f90c7adac6 Avoid infinite loop in circshift for infinite matrices
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
127 %! x = [1, 2, 3; 4, 5, 6; 7, 8, 9];
52f90c7adac6 Avoid infinite loop in circshift for infinite matrices
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
128
52f90c7adac6 Avoid infinite loop in circshift for infinite matrices
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
129 %!assert (circshift (x, 1), [7, 8, 9; 1, 2, 3; 4, 5, 6])
52f90c7adac6 Avoid infinite loop in circshift for infinite matrices
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
130 %!assert (circshift (x, -2), [7, 8, 9; 1, 2, 3; 4, 5, 6])
13277
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
131 %!assert (circshift (x, [0, 1]), [3, 1, 2; 6, 4, 5; 9, 7, 8])
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
132 %!assert (circshift ([], 1), [])
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
133
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
134 %!assert (circshift (eye (3), 1), circshift (eye (3), 1))
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
135 %!assert (circshift (eye (3), 1), [0,0,1;1,0,0;0,1,0])
12351
ca1190196d26 PermMatrix.cc (operator*): fix mixed row/column case
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
136
20749
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
137 %!assert (circshift (x, -2, 1), [7, 8, 9; 1, 2, 3; 4, 5, 6])
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
138 %!assert (circshift (x, 1, 2), [3, 1, 2; 6, 4, 5; 9, 7, 8])
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
139
26155
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
140 %!test <*53178> assert (circshift (1:4, 1), [4 1 2 3])
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
141 %!test <*53178> assert (circshift (1:4, 1, 1), 1:4)
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
142
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
143 ## Test input validation
28886
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28789
diff changeset
144 %!error <Invalid call> circshift ()
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28789
diff changeset
145 %!error <Invalid call> circshift (1)
20749
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
146 %!error <N must be a scalar> circshift (1, [2 3], 4)
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
147 %!error <N must be a vector> circshift (1, ones (2,2))
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
148 %!error <no longer than the number of dimensions in X> circshift (1, [1 2 3])
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
149 %!error <all values of N must be integers> circshift (1, 1.5)