Mercurial > hg > octave-nkf
annotate scripts/general/rot90.m @ 15148:1b2fbc30e4e7
Postfix increment and decrement operations in JIT
* jit-typeinfo.cc (jit_typeinfo::jit_typeinfo): Initialize copy operation.
* jit-typeinfo.h (jit_typeinfo::copy): New function.
* pt-jit.cc (jit_convert::visit_postfix_expression): Implement for ++ and --.
author | Max Brister <max@2bass.com> |
---|---|
date | Fri, 10 Aug 2012 16:41:07 -0500 |
parents | 5d3a684236b0 |
children | d63878346099 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13287
diff
changeset
|
1 ## Copyright (C) 1993-2012 John W. Eaton |
2313 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
245 | 18 |
3369 | 19 ## -*- texinfo -*- |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
20 ## @deftypefn {Function File} {} rot90 (@var{A}) |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
21 ## @deftypefnx {Function File} {} rot90 (@var{A}, @var{k}) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
22 ## Return a copy of @var{A} with the elements rotated counterclockwise in |
3369 | 23 ## 90-degree increments. The second argument is optional, and specifies |
24 ## how many 90-degree rotations are to be applied (the default value is 1). | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
25 ## Negative values of @var{k} rotate the matrix in a clockwise direction. |
3369 | 26 ## For example, |
3426 | 27 ## |
3369 | 28 ## @example |
29 ## @group | |
30 ## rot90 ([1, 2; 3, 4], -1) | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
31 ## @result{} 3 1 |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
32 ## 4 2 |
3369 | 33 ## @end group |
34 ## @end example | |
3426 | 35 ## |
3369 | 36 ## @noindent |
37 ## rotates the given matrix clockwise by 90 degrees. The following are all | |
38 ## equivalent statements: | |
3426 | 39 ## |
3369 | 40 ## @example |
41 ## @group | |
42 ## rot90 ([1, 2; 3, 4], -1) | |
43 ## rot90 ([1, 2; 3, 4], 3) | |
44 ## rot90 ([1, 2; 3, 4], 7) | |
45 ## @end group | |
46 ## @end example | |
4869 | 47 ## |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
48 ## Note that @code{rot90} only works with 2-D arrays. To rotate N-D arrays |
4869 | 49 ## use @code{rotdim} instead. |
5642 | 50 ## @seealso{rotdim, flipud, fliplr, flipdim} |
3369 | 51 ## @end deftypefn |
4 | 52 |
2314 | 53 ## Author: jwe |
54 | |
12862
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
55 function B = rot90 (A, k = 1) |
4869 | 56 |
12862
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
57 if (nargin < 1 || nargin > 2) |
6046 | 58 print_usage (); |
4 | 59 endif |
60 | |
12862
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
61 if (ndims (A) > 2) |
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
62 error ("rot90: A must be a 2-D array"); |
13287
5c22edebf2e8
rot90.m: Simplify function by using mod() rather than rem()
Rik <octave@nomad.inbox5.com>
parents:
12862
diff
changeset
|
63 elseif (! (isscalar (k) && isreal (k) && k == fix (k))) |
12862
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
64 error ("rot90: K must be a single real integer"); |
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
65 endif |
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
66 |
13287
5c22edebf2e8
rot90.m: Simplify function by using mod() rather than rem()
Rik <octave@nomad.inbox5.com>
parents:
12862
diff
changeset
|
67 k = mod (k, 4); |
12862
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
68 |
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
69 if (k == 0) |
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
70 B = A; |
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
71 elseif (k == 1) |
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
72 B = flipud (A.'); |
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
73 elseif (k == 2) |
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
74 B = flipud (fliplr (A)); |
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
75 elseif (k == 3) |
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
76 B = (flipud (A)).'; |
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
77 else |
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
78 error ("rot90: internal error!"); |
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
79 endif |
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
80 |
4 | 81 endfunction |
7411 | 82 |
12862
a9d292ce5489
rot90.m: Put input validation first. Update tests to include input validation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
83 |
7411 | 84 %!test |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
85 %! x1 = [1, 2; 3, 4]; |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
86 %! x2 = [2, 4; 1, 3]; |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
87 %! x3 = [4, 3; 2, 1]; |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
88 %! x4 = [3, 1; 4, 2]; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
89 %! |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
90 %! assert (rot90 (x1), x2); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
91 %! assert (rot90 (x1, 2), x3); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
92 %! assert (rot90 (x1, 3), x4); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
93 %! assert (rot90 (x1, 4), x1); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
94 %! assert (rot90 (x1, 5), x2); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
95 %! assert (rot90 (x1, -1), x4); |
7411 | 96 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
97 %% Test input validation |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
98 %!error rot90 () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
99 %!error rot90 (1, 2, 3) |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
100 %!error rot90 (1, ones (2)) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
101 %!error rot90 (1, 1.5) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
102 %!error rot90 (1, 1+i) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
103 |