Mercurial > hg > octave-lyh
annotate scripts/set/unique.m @ 16618:13728d41fb6a
use functions to handle colors in Windows GUI terminal
* QWinTerminalImpl.cpp (QConsolePrivate::backgroundColor,
QConsolePrivate::foregroundColor, QConsolePrivate::selectionColor,
QConsolePrivate::cursorColor, QConsolePrivate::setBackgroundColor,
QConsolePrivate::setForegroundColor,
QConsolePrivate::setSelectionColor, QConsolePrivate::setCursorColor):
New functions.
(QConsolePrivate::m_backgroundColor,
QConsolePrivate::m_foregroundColor): Delete member variables.
(QConsolePrivate::QConsolePrivate): Call setBackgroundColor and
setForegroundColor to set default colors.
(QWinTerminalImpl::viewPaintEvent): Use functions to access colors.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 May 2013 02:20:01 -0400 |
parents | 51b13fe45a94 |
children | bc924baa2c4e |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
1 ## Copyright (C) 2000-2012 Paul Kienzle |
11523 | 2 ## Copyright (C) 2008-2009 Jaroslav Hajek |
7016 | 3 ## |
4 ## This file is part of Octave. | |
5165 | 5 ## |
7016 | 6 ## Octave is free software; you can redistribute it and/or modify it |
7 ## under the terms of the GNU General Public License as published by | |
8 ## the Free Software Foundation; either version 3 of the License, or (at | |
9 ## your option) any later version. | |
5165 | 10 ## |
7016 | 11 ## Octave is distributed in the hope that it will be useful, but |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
5165 | 15 ## |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
5165 | 19 |
20 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10373
diff
changeset
|
21 ## @deftypefn {Function File} {} unique (@var{x}) |
8887 | 22 ## @deftypefnx {Function File} {} unique (@var{x}, "rows") |
23 ## @deftypefnx {Function File} {} unique (@dots{}, "first") | |
24 ## @deftypefnx {Function File} {} unique (@dots{}, "last") | |
25 ## @deftypefnx {Function File} {[@var{y}, @var{i}, @var{j}] =} unique (@dots{}) | |
5165 | 26 ## Return the unique elements of @var{x}, sorted in ascending order. |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
27 ## If the input @var{x} is a vector then the output is also a vector with the |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
28 ## same orientation (row or column) as the input. For a matrix input the |
10882
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
29 ## output is always a column vector. @var{x} may also be a cell array of |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
30 ## strings. |
5165 | 31 ## |
8887 | 32 ## If the optional argument @code{"rows"} is supplied, return the unique |
33 ## rows of @var{x}, sorted in ascending order. | |
5165 | 34 ## |
8887 | 35 ## If requested, return index vectors @var{i} and @var{j} such that |
36 ## @code{x(i)==y} and @code{y(j)==x}. | |
37 ## | |
10882
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
38 ## Additionally, if @var{i} is a requested output then one of @code{"first"} or |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
39 ## @code{"last"} may be given as an input. If @code{"last"} is specified, |
10882
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
40 ## return the highest possible indices in @var{i}, otherwise, if @code{"first"} |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
41 ## is specified, return the lowest. The default is @code{"last"}. |
5642 | 42 ## @seealso{union, intersect, setdiff, setxor, ismember} |
5165 | 43 ## @end deftypefn |
44 | |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
45 function [y, i, j] = unique (x, varargin) |
5165 | 46 |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
47 if (nargin < 1) |
6046 | 48 print_usage (); |
5165 | 49 endif |
50 | |
8412
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
51 if (nargin > 1) |
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
52 ## parse options |
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
53 if (iscellstr (varargin)) |
16221
51b13fe45a94
unique.m: Avoid recursion in checking input arguments.
Rik <rik@octave.org>
parents:
16217
diff
changeset
|
54 optfirst = strcmp ("first", varargin); |
51b13fe45a94
unique.m: Avoid recursion in checking input arguments.
Rik <rik@octave.org>
parents:
16217
diff
changeset
|
55 optlast = strcmp ("last", varargin); |
51b13fe45a94
unique.m: Avoid recursion in checking input arguments.
Rik <rik@octave.org>
parents:
16217
diff
changeset
|
56 optrows = strcmp ("rows", varargin); |
51b13fe45a94
unique.m: Avoid recursion in checking input arguments.
Rik <rik@octave.org>
parents:
16217
diff
changeset
|
57 if (! all (optfirst | optlast | optrows)) |
51b13fe45a94
unique.m: Avoid recursion in checking input arguments.
Rik <rik@octave.org>
parents:
16217
diff
changeset
|
58 error ("unique: invalid option"); |
51b13fe45a94
unique.m: Avoid recursion in checking input arguments.
Rik <rik@octave.org>
parents:
16217
diff
changeset
|
59 endif |
51b13fe45a94
unique.m: Avoid recursion in checking input arguments.
Rik <rik@octave.org>
parents:
16217
diff
changeset
|
60 optfirst = any (optfirst); |
51b13fe45a94
unique.m: Avoid recursion in checking input arguments.
Rik <rik@octave.org>
parents:
16217
diff
changeset
|
61 optlast = any (optlast); |
51b13fe45a94
unique.m: Avoid recursion in checking input arguments.
Rik <rik@octave.org>
parents:
16217
diff
changeset
|
62 optrows = any (optrows); |
8412
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
63 if (optfirst && optlast) |
10882
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
64 error ('unique: cannot specify both "last" and "first"'); |
8412
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
65 endif |
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
66 else |
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
67 error ("unique: options must be strings"); |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
68 endif |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
69 |
8412
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
70 if (optrows && iscell (x)) |
10882
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
71 warning ('unique: "rows" is ignored for cell arrays'); |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
72 optrows = false; |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
73 endif |
8412
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
74 else |
10882
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
75 optfirst = false; |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
76 optrows = false; |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
77 endif |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
78 |
10373
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
79 ## FIXME -- the operations |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
80 ## |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
81 ## match = (y(1:n-1) == y(2:n)); |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
82 ## y(idx) = []; |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
83 ## |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
84 ## are very slow on sparse matrices. Until they are fixed to be as |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
85 ## fast as for full matrices, operate on the nonzero elements of the |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
86 ## sparse array as long as we are not operating on rows. |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
87 |
11097
ffb2f1ef2097
make issparse, sparse, and spalloc built-in functions
John W. Eaton <jwe@octave.org>
parents:
10885
diff
changeset
|
88 if (issparse (x) && ! optrows && nargout <= 1) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11563
diff
changeset
|
89 if (nnz (x) < numel (x)) |
11097
ffb2f1ef2097
make issparse, sparse, and spalloc built-in functions
John W. Eaton <jwe@octave.org>
parents:
10885
diff
changeset
|
90 y = unique ([0; (full (nonzeros (x)))], varargin{:}); |
ffb2f1ef2097
make issparse, sparse, and spalloc built-in functions
John W. Eaton <jwe@octave.org>
parents:
10885
diff
changeset
|
91 else |
ffb2f1ef2097
make issparse, sparse, and spalloc built-in functions
John W. Eaton <jwe@octave.org>
parents:
10885
diff
changeset
|
92 ## Corner case where sparse matrix is actually full |
ffb2f1ef2097
make issparse, sparse, and spalloc built-in functions
John W. Eaton <jwe@octave.org>
parents:
10885
diff
changeset
|
93 y = unique (full (x), varargin{:}); |
10373
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
94 endif |
11097
ffb2f1ef2097
make issparse, sparse, and spalloc built-in functions
John W. Eaton <jwe@octave.org>
parents:
10885
diff
changeset
|
95 return; |
10373
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
96 endif |
1f11fabfa349
improve performance of unique for sparse arrays
John W. Eaton <jwe@octave.org>
parents:
10372
diff
changeset
|
97 |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
98 if (optrows) |
10882
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
99 n = rows (x); |
8502
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
100 dim = 1; |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
101 else |
6609 | 102 n = numel (x); |
10882
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
103 dim = (rows (x) == 1) + 1; |
5165 | 104 endif |
105 | |
5168 | 106 y = x; |
10882
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
107 ## Special cases 0 and 1 |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
108 if (n == 0) |
10372
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
109 if (! optrows && isempty (x) && any (size (x))) |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
110 if (iscell (y)) |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
111 y = cell (0, 1); |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
112 else |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
113 y = zeros (0, 1, class (y)); |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
114 endif |
634e182d34e4
unique.m: return 0x1 for empty matrices with some nonzero dims; preserve class of argument; new tests
John W. Eaton <jwe@octave.org>
parents:
10088
diff
changeset
|
115 endif |
5165 | 116 i = j = []; |
5168 | 117 return; |
10882
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
118 elseif (n == 1) |
5165 | 119 i = j = 1; |
5168 | 120 return; |
5165 | 121 endif |
122 | |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
123 if (optrows) |
10882
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
124 if (nargout > 1) |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
125 [y, i] = sortrows (y); |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
126 else |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
127 y = sortrows (y); |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
128 endif |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
129 match = all (y(1:n-1,:) == y(2:n,:), 2); |
5165 | 130 idx = find (match); |
5168 | 131 y(idx,:) = []; |
5165 | 132 else |
10882
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
133 if (! isvector (y)) |
5168 | 134 y = y(:); |
135 endif | |
10882
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
136 if (nargout > 1) |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
137 [y, i] = sort (y); |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
138 else |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
139 y = sort (y); |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
140 endif |
5205 | 141 if (iscell (y)) |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
142 match = strcmp (y(1:n-1), y(2:n)); |
5205 | 143 else |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
144 match = (y(1:n-1) == y(2:n)); |
5205 | 145 endif |
5165 | 146 idx = find (match); |
5168 | 147 y(idx) = []; |
5165 | 148 endif |
149 | |
10882
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
150 if (isargout (3)) |
5165 | 151 j = i; |
8502
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
152 if (dim == 1) |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
153 j(i) = cumsum ([1; !match]); |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
154 else |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
155 j(i) = cumsum ([1, !match]); |
8610
85c9906abfd1
use endif and endfor instead of end
John W. Eaton <jwe@octave.org>
parents:
8502
diff
changeset
|
156 endif |
5165 | 157 endif |
8412
970b4dbff9e4
optimize unique called with a single argument
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7920
diff
changeset
|
158 |
10882
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
159 if (isargout (2)) |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
160 if (optfirst) |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
161 i(idx+1) = []; |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
162 else |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
163 i(idx) = []; |
055b95863699
unique.m: Improve performance by only calculating necessary outputs.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
164 endif |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
165 endif |
5165 | 166 |
167 endfunction | |
168 | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
169 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
170 %!assert (unique ([1 1 2; 1 2 1; 1 1 2]),[1;2]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
171 %!assert (unique ([1 1 2; 1 0 1; 1 1 2],"rows"),[1 0 1; 1 1 2]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
172 %!assert (unique ([]),[]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
173 %!assert (unique ([1]),[1]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
174 %!assert (unique ([1 2]),[1 2]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
175 %!assert (unique ([1;2]),[1;2]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
176 %!assert (unique ([1,NaN,Inf,NaN,Inf]),[1,Inf,NaN,NaN]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
177 %!assert (unique ({"Foo","Bar","Foo"}),{"Bar","Foo"}) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
178 %!assert (unique ({"Foo","Bar","FooBar"}'),{"Bar","Foo","FooBar"}') |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
179 %!assert (unique (zeros (1,0)), zeros (0,1)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
180 %!assert (unique (zeros (1,0), "rows"), zeros (1,0)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
181 %!assert (unique (cell (1,0)), cell (0,1)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
182 %!assert (unique ({}), {}) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
183 %!assert (unique ([1,2,2,3,2,4], "rows"), [1,2,2,3,2,4]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
184 %!assert (unique ([1,2,2,3,2,4]), [1,2,3,4]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
185 %!assert (unique ([1,2,2,3,2,4]', "rows"), [1,2,3,4]') |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
186 %!assert (unique (sparse ([2,0;2,0])), [0,2]') |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
187 %!assert (unique (sparse ([1,2;2,3])), [1,2,3]') |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
188 %!assert (unique ([1,2,2,3,2,4]', "rows"), [1,2,3,4]') |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
189 %!assert (unique (single ([1,2,2,3,2,4]), "rows"), single ([1,2,2,3,2,4])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
190 %!assert (unique (single ([1,2,2,3,2,4])), single ([1,2,3,4])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
191 %!assert (unique (single ([1,2,2,3,2,4]'), "rows"), single ([1,2,3,4]')) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
192 %!assert (unique (uint8 ([1,2,2,3,2,4]), "rows"), uint8 ([1,2,2,3,2,4])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
193 %!assert (unique (uint8 ([1,2,2,3,2,4])), uint8 ([1,2,3,4])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
194 %!assert (unique (uint8 ([1,2,2,3,2,4]'), "rows"), uint8 ([1,2,3,4]')) |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
195 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
196 %! [a,i,j] = unique ([1,1,2,3,3,3,4]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
197 %! assert (a, [1,2,3,4]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
198 %! assert (i, [2,3,6,7]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
199 %! assert (j, [1,1,2,3,3,3,4]); |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
200 %! |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
201 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
202 %! [a,i,j] = unique ([1,1,2,3,3,3,4]', "first"); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
203 %! assert (a, [1,2,3,4]'); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
204 %! assert (i, [1,3,4,7]'); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
205 %! assert (j, [1,1,2,3,3,3,4]'); |
8502
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
206 %! |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
207 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
208 %! [a,i,j] = unique ({"z"; "z"; "z"}); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
209 %! assert (a, {"z"}); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
210 %! assert (i, [3]'); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
211 %! assert (j, [1;1;1]); |
8502
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
212 %! |
d437e8dc18fa
make unique work for row vectors
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
8413
diff
changeset
|
213 %!test |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
214 %! A = [1,2,3;1,2,3]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
215 %! [a,i,j] = unique (A, "rows"); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
216 %! assert (a, [1,2,3]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
217 %! assert (A(i,:), a); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
218 %! assert (a(j,:), A); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
219 |
16217
1f1e248caeab
unique.m: Correctly check invalid options (bug #38460)
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
220 %!error unique({"a", "b", "c"}, "UnknownOption") |
1f1e248caeab
unique.m: Correctly check invalid options (bug #38460)
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
221 %!error unique({"a", "b", "c"}, "UnknownOption1", "UnknownOption2") |
1f1e248caeab
unique.m: Correctly check invalid options (bug #38460)
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
222 %!error unique({"a", "b", "c"}, "rows", "UnknownOption2") |
1f1e248caeab
unique.m: Correctly check invalid options (bug #38460)
Julien Bect <julien.bect@supelec.fr>
parents:
14363
diff
changeset
|
223 %!error unique({"a", "b", "c"}, "UnknownOption1", "last") |