Mercurial > octave
annotate scripts/set/intersect.m @ 30564:796f54d4ddbf stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
In all .txi and .texi files except gpl.txi and gpl.texi in the
doc/liboctave and doc/interpreter directories, change the copyright
to "Octave Project Developers", the same as used for other source
files. Update copyright notices for 2022 (not done since 2019). For
gpl.txi and gpl.texi, change the copyright notice to be "Free Software
Foundation, Inc." and leave the date at 2007 only because this file
only contains the text of the GPL, not anything created by the Octave
Project Developers.
Add Paul Thomas to contributors.in.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Dec 2021 18:22:40 -0500 |
parents | 0a5b15007766 |
children | 597f3ee61a48 |
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 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
3 ## Copyright (C) 2000-2022 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27797
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/>. |
5820 | 7 ## |
8 ## This file is part of Octave. | |
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 |
5820 | 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. |
5820 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
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. |
5820 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 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 ######################################################################## |
5820 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20440
diff
changeset
|
27 ## @deftypefn {} {@var{c} =} intersect (@var{a}, @var{b}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20440
diff
changeset
|
28 ## @deftypefnx {} {@var{c} =} intersect (@var{a}, @var{b}, "rows") |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
29 ## @deftypefnx {} {@var{c} =} intersect (@dots{}, "sorted") |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
30 ## @deftypefnx {} {@var{c} =} intersect (@dots{}, "stable") |
27229
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
31 ## @deftypefnx {} {@var{c} =} intersect (@dots{}, "legacy") |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20440
diff
changeset
|
32 ## @deftypefnx {} {[@var{c}, @var{ia}, @var{ib}] =} intersect (@dots{}) |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
33 ## |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
34 ## Return the unique elements common to both @var{a} and @var{b}. |
5820 | 35 ## |
19974
72ccbd36e23c
Return a column vector by default for Matlab compatibility (bug #44425, bug #44453).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
36 ## If @var{a} and @var{b} are both row vectors then return a row vector; |
72ccbd36e23c
Return a column vector by default for Matlab compatibility (bug #44425, bug #44453).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
37 ## Otherwise, return a column vector. The inputs may also be cell arrays of |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
38 ## strings. |
5820 | 39 ## |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
40 ## If the optional input @qcode{"rows"} is given then return the common rows of |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
41 ## @var{a} and @var{b}. The inputs must be 2-D numeric matrices to use this |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
42 ## option. |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
43 ## |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
44 ## The optional argument @qcode{"sorted"}/@qcode{"stable"} controls the order |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
45 ## in which unique values appear in the output. The default is |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
46 ## @qcode{"sorted"} and values in the output are placed in ascending order. |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
47 ## The alternative @qcode{"stable"} preserves the order found in the input. |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
48 ## |
27229
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
49 ## If requested, return column index vectors @var{ia} and @var{ib} such that |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
50 ## @code{@var{c} = @var{a}(@var{ia})} and @code{@var{c} = @var{b}(@var{ib})}. |
5820 | 51 ## |
27235
e12571df6466
doc: Update description of "legacy" option for set functions.
Rik <rik@octave.org>
parents:
27229
diff
changeset
|
52 ## Programming Note: The input flag @qcode{"legacy"} changes the algorithm |
e12571df6466
doc: Update description of "legacy" option for set functions.
Rik <rik@octave.org>
parents:
27229
diff
changeset
|
53 ## to be compatible with @sc{matlab} releases prior to R2012b. |
27229
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
54 ## |
24932
e178a73af18e
doc: move @seealso lists inside the function doc string block
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
55 ## @seealso{unique, union, setdiff, setxor, ismember} |
5820 | 56 ## @end deftypefn |
57 | |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
58 function [c, ia, ib] = intersect (a, b, varargin) |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
59 |
27229
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
60 if (nargin < 2 || nargin > 4) |
6046 | 61 print_usage (); |
5820 | 62 endif |
63 | |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
64 [a, b] = validsetargs ("intersect", a, b, varargin{:}); |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
65 |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
66 ## Special case of empty matrices |
5820 | 67 if (isempty (a) || isempty (b)) |
20440
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
68 ## Lots of type checking required for Matlab compatibility. |
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
69 if (isnumeric (a) && isnumeric (b)) |
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
70 c = []; |
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
71 elseif (iscell (b)) |
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
72 c = {}; |
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
73 else |
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
74 c = ""; |
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
75 endif |
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
76 ia = ib = []; |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
77 return; |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
78 endif |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
79 |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
80 by_rows = any (strcmp ("rows", varargin)); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
81 optsorted = ! any (strcmp ("stable", varargin)); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
82 optlegacy = any (strcmp ("legacy", varargin)); |
27229
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
83 |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
84 if (optlegacy) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
85 isrowvec = ! iscolumn (a) || ! iscolumn (b); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
86 else |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
87 isrowvec = isrow (a) && isrow (b); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
88 endif |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
89 |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
90 ## Form A and B into sets |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
91 if (nargout > 1 || ! optsorted) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
92 [a, ia] = unique (a, varargin{:}); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
93 ia = ia(:); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
94 [b, ib] = unique (b, varargin{:}); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
95 ib = ib(:); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
96 else |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
97 a = unique (a, varargin{:}); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
98 b = unique (b, varargin{:}); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
99 endif |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
100 |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
101 if (by_rows) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
102 c = [a; b]; |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
103 if (nargout > 1 || ! optsorted) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
104 [c, ic] = sortrows (c); |
9108 | 105 else |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
106 c = sortrows (c); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
107 endif |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
108 match = find (all (c(1:end-1,:) == c(2:end,:), 2)); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
109 if (optsorted) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
110 c = c(match, :); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
111 else |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
112 c = [a; b]; |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
113 ## FIXME: Is there a way to avoid a call to sort? |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
114 c = c(sort (ic(match)), :); |
6825 | 115 endif |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
116 len_a = rows (a); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
117 else |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
118 c = [a(:); b(:)]; |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
119 if (nargout > 1 || ! optsorted) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
120 [c, ic] = sort (c); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
121 else |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
122 c = sort (c); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
123 endif |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
124 if (iscellstr (c)) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
125 match = find (strcmp (c(1:end-1), c(2:end))); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
126 else |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
127 match = find (c(1:end-1) == c(2:end)); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
128 endif |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
129 len_a = length (a); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
130 if (optsorted) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
131 c = c(match); |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
132 else |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
133 c = [a(:); b(:)]; |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
134 ## FIXME: Is there a way to avoid a call to sort? |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
135 c = c(sort (ic(match))); |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
136 endif |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
137 |
29190
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
138 ## Adjust output orientation for Matlab compatibility |
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
139 if (isrowvec) |
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
140 c = c.'; |
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
141 endif |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
142 endif |
5820 | 143 |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
144 if (nargout > 1) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
145 ia = ia(ic(match)); # a(ia) == c |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
146 ib = ib(ic(match+1) - len_a); # b(ib) == c |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
147 if (! optsorted) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
148 ## FIXME: Is there a way to avoid a call to sort? |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
149 ia = sort (ia); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
150 [~, idx] = min (ib); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
151 ib = [ib(idx:end); ib(1:idx-1)]; |
27229
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
152 endif |
29190
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
153 if (optlegacy && isrowvec && ! by_rows) |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
154 ia = ia.'; |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
155 ib = ib.'; |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
156 endif |
5820 | 157 endif |
158 | |
159 endfunction | |
160 | |
161 | |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
162 %!assert (intersect ([1 2 3 4], [9 8 4 2]), [2, 4]) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
163 %!assert (intersect ([1 2; 2 3; 4 5], [2 3; 3 4; 5 6], "rows"), [2 3]) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
164 %!assert (intersect ([1 NaN], [NaN NaN 5]), zeros (1,0)) |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
165 |
27296
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27295
diff
changeset
|
166 %!test |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27295
diff
changeset
|
167 %! a = [1 1 1 2 2 2]; |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27295
diff
changeset
|
168 %! b = [1 2 3 4 5 6]; |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27295
diff
changeset
|
169 %! c = intersect (a, b); |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27295
diff
changeset
|
170 %! assert (c, [1,2]); |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27295
diff
changeset
|
171 |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
172 ## Test multi-dimensional arrays |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
173 %!test |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
174 %! a = rand (3,3,3); |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
175 %! b = a; |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
176 %! b(1,1,1) = 2; |
19974
72ccbd36e23c
Return a column vector by default for Matlab compatibility (bug #44425, bug #44453).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
177 %! assert (intersect (a, b), sort (a(2:end)')); |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
178 |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
179 ## Test the routine for index vectors ia and ib |
5820 | 180 %!test |
181 %! a = [3 2 4 5 7 6 5 1 0 13 13]; | |
182 %! b = [3 5 12 1 1 7]; | |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
183 %! [c, ia, ib] = intersect (a, b); |
27226
6eb32f0aea87
Implement "legacy" flag for intersect function (bug #56592).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
184 %! assert (c, [1, 3, 5, 7]); |
6eb32f0aea87
Implement "legacy" flag for intersect function (bug #56592).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
185 %! assert (ia, [8; 1; 4; 5]); |
6eb32f0aea87
Implement "legacy" flag for intersect function (bug #56592).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
186 %! assert (ib, [4; 1; 2; 6]); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14148
diff
changeset
|
187 %! assert (a(ia), c); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14148
diff
changeset
|
188 %! assert (b(ib), c); |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
189 |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
190 ## Test "rows" argument |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
191 %!test |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
192 %! a = [1,1,2;1,4,5;2,1,7]; |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
193 %! b = [1,4,5;2,3,4;1,1,2;9,8,7]; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14148
diff
changeset
|
194 %! [c,ia,ib] = intersect (a, b, "rows"); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14148
diff
changeset
|
195 %! assert (c, [1,1,2;1,4,5]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14148
diff
changeset
|
196 %! assert (ia, [1;2]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14148
diff
changeset
|
197 %! assert (ib, [3;1]); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14148
diff
changeset
|
198 %! assert (a(ia,:), c); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14148
diff
changeset
|
199 %! assert (b(ib,:), c); |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
200 |
14148
402acc45350e
intersect.m: Properly handle the "rows" case with more than 1 output arg (bug #35247)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
201 %!test |
402acc45350e
intersect.m: Properly handle the "rows" case with more than 1 output arg (bug #35247)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
202 %! a = [1 2 3 4; 5 6 7 8; 9 10 11 12]; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14148
diff
changeset
|
203 %! [b, ia, ib] = intersect (a, a, "rows"); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14148
diff
changeset
|
204 %! assert (b, a); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14148
diff
changeset
|
205 %! assert (ia, [1:3]'); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14148
diff
changeset
|
206 %! assert (ib, [1:3]'); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14148
diff
changeset
|
207 |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
208 ## Test "stable" argument |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
209 %!test |
27296
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27295
diff
changeset
|
210 %! a = [2 2 2 1 1 1]; |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27295
diff
changeset
|
211 %! b = [1 2 3 4 5 6]; |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27295
diff
changeset
|
212 %! c = intersect (a, b, "stable"); |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27295
diff
changeset
|
213 %! assert (c, [2,1]); |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27295
diff
changeset
|
214 |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27295
diff
changeset
|
215 %!test |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
216 %! a = [3 2 4 5 7 6 5 1 0 13 13]; |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
217 %! b = [3 5 12 1 1 7]; |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
218 %! [c, ia, ib] = intersect (a, b, "stable"); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
219 %! assert (c, [3, 5, 7, 1]); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
220 %! assert (ia, [1; 4; 5; 8]); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
221 %! assert (ib, [1; 2; 6; 4]); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
222 %! assert (a(ia), c); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
223 %! assert (b(ib), c); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
224 |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
225 %!test |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
226 %! a = [1,4,5;1,1,2;2,1,7]; |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
227 %! b = [1,4,5;2,3,4;1,1,2;9,8,7]; |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
228 %! [c, ia, ib] = intersect (a, b, "rows", "stable"); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
229 %! assert (c, [1,4,5; 1,1,2]); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
230 %! assert (ia, [1;2]); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
231 %! assert (ib, [1;3]); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
232 %! assert (a(ia,:), c); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
233 %! assert (b(ib,:), c); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
234 |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
235 %!test |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
236 %! a = [1 2 3 4; 5 6 7 8; 9 10 11 12]; |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
237 %! [b, ia, ib] = intersect (a, a, "rows", "stable"); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
238 %! assert (b, a); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
239 %! assert (ia, [1:3]'); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
240 %! assert (ib, [1:3]'); |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
241 |
27229
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
242 ## Test "legacy" argument |
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
243 %!test |
27797
5dcdd5bd46e2
maint: remove trailing spaces from code.
Rik <rik@octave.org>
parents:
27296
diff
changeset
|
244 %! a = [7 1 7 7 4]; |
27229
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
245 %! b = [7 0 4 4 0]; |
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
246 %! [c, ia, ib] = intersect (a, b); |
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
247 %! assert (c, [4, 7]); |
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
248 %! assert (ia, [5; 1]); |
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
249 %! assert (ib, [3; 1]); |
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
250 %! [c, ia, ib] = intersect (a, b, "legacy"); |
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
251 %! assert (c, [4, 7]); |
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
252 %! assert (ia, [5, 4]); |
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
253 %! assert (ib, [4, 1]); |
255f2681d224
intersect.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
27226
diff
changeset
|
254 |
29190
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
255 %!test # "legacy" + "rows" |
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
256 %! A = [ 1 2; 3 4; 5 6; 3 4; 7 8 ]; |
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
257 %! B = [ 3 4; 7 8; 9 10 ]; |
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
258 %! [c, ia, ib] = intersect (A, B, "rows"); |
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
259 %! assert (c, [3, 4; 7, 8]); |
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
260 %! assert (ia, [2; 5]); |
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
261 %! assert (ib, [1; 2]); |
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
262 %! [c, ia, ib] = intersect (A, B, "rows", "legacy"); |
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
263 %! assert (c, [3, 4; 7, 8]); |
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
264 %! assert (ia, [4; 5]); |
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
265 %! assert (ib, [1; 2]); |
7f11d59e3af8
Fix incorrect results for set functions with "legacy" option (bug #59708).
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
266 |
27295
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
267 ## Test orientation of output |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
268 %!shared a,b |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
269 %! a = 1:4; |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
270 %! b = 2:5; |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
271 |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
272 %!assert (size (intersect (a, b)), [1, 3]) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
273 %!assert (size (intersect (a', b)), [3, 1]) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
274 %!assert (size (intersect (a, b')), [3, 1]) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
275 %!assert (size (intersect (a', b')), [3, 1]) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
276 %!assert (size (intersect (a, b, "legacy")), [1, 3]) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
277 %!assert (size (intersect (a', b, "legacy")), [1, 3]) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
278 %!assert (size (intersect (a, b', "legacy")), [1, 3]) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
279 %!assert (size (intersect (a', b', "legacy")), [3, 1]) |
7ec25367bdc5
intersect.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27235
diff
changeset
|
280 |
20440
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
281 ## Test return type of empty intersections |
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
282 %!assert (intersect (['a', 'b'], {}), {}) |
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
283 %!assert (intersect ([], {'a', 'b'}), {}) |
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
284 %!assert (intersect ([], {}), {}) |
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
285 %!assert (intersect ({'a', 'b'}, []), {}) |
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
286 %!assert (intersect ([], ['a', 'b']), "") |
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
287 %!assert (intersect ({}, []), {}) |
3fc21d7ac11c
intersect.m: Return same class of output as Matlab for empty input (bug #45686).
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
288 %!assert (intersect (['a', 'b'], []), "") |