annotate scripts/general/circshift.m @ 27918:b442ec6dda5c

use centralized file for copyright info for individual contributors * COPYRIGHT.md: New file. * In most other files, use "Copyright (C) YYYY-YYYY The Octave Project Developers" instead of tracking individual names in separate source files. The motivation is to reduce the effort required to update the notices each year. Until now, the Octave source files contained copyright notices that list individual contributors. I adopted these file-scope copyright notices because that is what everyone was doing 30 years ago in the days before distributed version control systems. But now, with many contributors and modern version control systems, having these file-scope copyright notices causes trouble when we update copyright years or refactor code. Over time, the file-scope copyright notices may become outdated as new contributions are made or code is moved from one file to another. Sometimes people contribute significant patches but do not add a line claiming copyright. Other times, people add a copyright notice for their contribution but then a later refactoring moves part or all of their contribution to another file and the notice is not moved with the code. As a practical matter, moving such notices is difficult -- determining what parts are due to a particular contributor requires a time-consuming search through the project history. Even managing the yearly update of copyright years is problematic. We have some contributors who are no longer living. Should we update the copyright dates for their contributions when we release new versions? Probably not, but we do still want to claim copyright for the project as a whole. To minimize the difficulty of maintaining the copyright notices, I would like to change Octave's sources to use what is described here: https://softwarefreedom.org/resources/2012/ManagingCopyrightInformation.html in the section "Maintaining centralized copyright notices": The centralized notice approach consolidates all copyright notices in a single location, usually a top-level file. This file should contain all of the copyright notices provided project contributors, unless the contribution was clearly insignificant. It may also credit -- without a copyright notice -- anyone who helped with the project but did not contribute code or other copyrighted material. This approach captures less information about contributions within individual files, recognizing that the DVCS is better equipped to record those details. As we mentioned before, it does have one disadvantage as compared to the file-scope approach: if a single file is separated from the distribution, the recipient won't see the contributors' copyright notices. But this can be easily remedied by including a single copyright notice in each file's header, pointing to the top-level file: Copyright YYYY-YYYY The Octave Project Developers See the COPYRIGHT file at the top-level directory of this distribution or at https://octave.org/COPYRIGHT.html. followed by the usual GPL copyright statement. For more background, see the discussion here: https://lists.gnu.org/archive/html/octave-maintainers/2020-01/msg00009.html Most files in the following directories have been skipped intentinally in this changeset: doc libgui/qterminal liboctave/external m4
author John W. Eaton <jwe@octave.org>
date Mon, 06 Jan 2020 15:38:17 -0500
parents f6730533820e
children 1891570abac8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26600
diff changeset
1 ## Copyright (C) 2004-2019 The Octave Project Developers
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26600
diff changeset
2 ##
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26600
diff changeset
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26600
diff changeset
4 ## or <https://octave.org/COPYRIGHT.html/>.
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26600
diff changeset
5 ##
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
6 ##
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
7 ## This file is part of Octave.
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
8 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
9 ## 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
10 ## 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
11 ## 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
12 ## (at your option) any later version.
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
13 ##
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
14 ## 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
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## GNU General Public License for more details.
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
18 ##
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
19 ## 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
20 ## 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
21 ## <https://www.gnu.org/licenses/>.
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
22
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
23 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20749
diff changeset
24 ## @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
25 ## @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
26 ## 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
27 ##
20749
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
28 ## @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
29 ## 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
30 ## 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
31 ## 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
32 ## 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
33 ## 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
34 ##
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
35 ## 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
36 ## 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
37 ##
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
38 ## Examples:
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
39 ##
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
40 ## @example
26155
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
41 ## 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
42 ## 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
43 ## 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
44 ## ## 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
45 ## 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
46 ## @result{}
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
47 ## 7 8 9
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
48 ## 1 2 3
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
49 ## 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
50 ## ## 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
51 ## 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
52 ## @result{}
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
53 ## 7 8 9
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
54 ## 1 2 3
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
55 ## 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
56 ## ## 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
57 ## 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
58 ## @result{}
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
59 ## 3 1 2
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
60 ## 6 4 5
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
61 ## 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
62 ## ## 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
63 ## 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
64 ## @result{}
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
65 ## 3 1 2
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
66 ## 6 4 5
f6730533820e doc: clean up doc example blocks for accuracy and consistent formatting
Mike Miller <mtmiller@octave.org>
parents: 26577
diff changeset
67 ## 9 7 8
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
68 ## @end example
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
69 ## @seealso{permute, ipermute, shiftdim}
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
70 ## @end deftypefn
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
71
20749
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
72 function y = circshift (x, n, dim)
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
73
20749
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
74 if (nargin < 2 || nargin > 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
75 print_usage ();
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
76 endif
13277
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
77
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
78 if (isempty (x))
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
79 y = x;
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
80 return;
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
81 endif
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
82
26155
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
83 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
84 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
85
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
86 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
87 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
88 ## 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
89 (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
90 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
91 endif
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
92 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
93 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
94 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
95 endif
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
96 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
97 endif
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
98
13277
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
99 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
100 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
101 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
102 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
103 endif
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
104
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
105 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
106 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
107 b = n(i);
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
108 d = sz(i);
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
109 if (b > 0)
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
110 b = rem (b, d);
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
111 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
112 elseif (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 (abs (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} = [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
115 endif
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
116 endfor
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
117
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
118 y = x(idx{:});
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
119
4894
ab5870f984d9 [project @ 2004-06-03 19:32:02 by jwe]
jwe
parents:
diff changeset
120 endfunction
7614
52f90c7adac6 Avoid infinite loop in circshift for infinite matrices
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
121
13277
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
122
7614
52f90c7adac6 Avoid infinite loop in circshift for infinite matrices
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
123 %!shared x
52f90c7adac6 Avoid infinite loop in circshift for infinite matrices
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
124 %! 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
125
52f90c7adac6 Avoid infinite loop in circshift for infinite matrices
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
126 %!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
127 %!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
128 %!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
129 %!assert (circshift ([], 1), [])
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
130
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
131 %!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
132 %!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
133
20749
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
134 %!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
135 %!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
136
26155
8be616a0b9aa circshift.m: shift first non-singleton dimension if DIM not provided (bug #53178).
Rik <rik@octave.org>
parents: 25054
diff changeset
137 %!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
138 %!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
139
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
140 ## Test input validation
13277
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
141 %!error circshift ()
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
142 %!error circshift (1)
9f2e568123ea circshift.m: Recode to do away with some for loops.
Rik <octave@nomad.inbox5.com>
parents: 12575
diff changeset
143 %!error circshift (1,2,3)
20749
74cc8ae4e2b0 circshift.m: Overhaul function to support a third argument DIM (bug #46514).
Rik <rik@octave.org>
parents: 20158
diff changeset
144 %!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
145 %!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
146 %!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
147 %!error <all values of N must be integers> circshift (1, 1.5)