Mercurial > octave
annotate scripts/set/setxor.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 | 538468f901dd |
children | 1891570abac8 |
rev | line source |
---|---|
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27296
diff
changeset
|
1 ## Copyright (C) 2006-2019 The Octave Project Developers |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27296
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27296
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:
27296
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:
27296
diff
changeset
|
5 ## |
5825 | 6 ## |
7 ## This file is part of Octave. | |
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 |
22802
0dcff7695e26
maint: Update more Copyright statements to use standard form.
Rik <rik@octave.org>
parents:
22755
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. |
5825 | 13 ## |
22802
0dcff7695e26
maint: Update more Copyright statements to use standard form.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
14 ## Octave is distributed in the hope that it will be useful, but |
0dcff7695e26
maint: Update more Copyright statements to use standard form.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
0dcff7695e26
maint: Update more Copyright statements to use standard form.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0dcff7695e26
maint: Update more Copyright statements to use standard form.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
17 ## GNU General Public License for more details. |
5825 | 18 ## |
19 ## You should have received a copy of the GNU General Public License | |
7016 | 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/>. |
5825 | 22 |
23 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
24 ## @deftypefn {} {@var{c} =} setxor (@var{a}, @var{b}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
25 ## @deftypefnx {} {@var{c} =} setxor (@var{a}, @var{b}, "rows") |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
26 ## @deftypefnx {} {@var{c} =} setxor (@dots{}, "sorted") |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
27 ## @deftypefnx {} {@var{c} =} setxor (@dots{}, "stable") |
27238
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
28 ## @deftypefnx {} {@var{c} =} setxor (@dots{}, "legacy") |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20437
diff
changeset
|
29 ## @deftypefnx {} {[@var{c}, @var{ia}, @var{ib}] =} setxor (@dots{}) |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
30 ## |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
31 ## Return the unique elements exclusive to sets @var{a} or @var{b}. |
5825 | 32 ## |
19974
72ccbd36e23c
Return a column vector by default for Matlab compatibility (bug #44425, bug #44453).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
33 ## 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
|
34 ## 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:
18081
diff
changeset
|
35 ## strings. |
5825 | 36 ## |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
37 ## If the optional input @qcode{"rows"} is given then return the rows exclusive |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
38 ## to sets @var{a} and @var{b}. The inputs must be 2-D numeric matrices to use |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
39 ## this option. |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
40 ## |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
41 ## The optional argument @qcode{"sorted"}/@qcode{"stable"} controls the order |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
42 ## in which unique values appear in the output. The default is |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
43 ## @qcode{"sorted"} and values in the output are placed in ascending order. |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
44 ## The alternative @qcode{"stable"} preserves the order found in the input. |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
45 ## |
27238
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
46 ## The optional outputs @var{ia} and @var{ib} are column index vectors such |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
47 ## that @code{@var{a}(@var{ia})} and @code{@var{b}(@var{ib})} are disjoint sets |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
48 ## whose union is @var{c}. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
49 ## |
27238
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
50 ## Programming Note: The input flag @qcode{"legacy"} changes the algorithm |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
51 ## to be compatible with @sc{matlab} releases prior to R2012b. |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
52 ## |
5825 | 53 ## @seealso{unique, union, intersect, setdiff, ismember} |
54 ## @end deftypefn | |
55 | |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
56 function [c, ia, ib] = setxor (a, b, varargin) |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
57 |
27238
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
58 if (nargin < 2 || nargin > 4) |
6046 | 59 print_usage (); |
5825 | 60 endif |
61 | |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
62 [a, b] = validsetargs ("setxor", a, b, varargin{:}); |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
63 |
27238
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
64 by_rows = any (strcmp ("rows", varargin)); |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
65 optsorted = ! any (strcmp ("stable", varargin)); |
27238
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
66 optlegacy = any (strcmp ("legacy", varargin)); |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
67 |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
68 if (optlegacy) |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
69 isrowvec = ! iscolumn (a) || ! iscolumn (b); |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
70 else |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
71 isrowvec = isrow (a) && isrow (b); |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
72 endif |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
73 |
5825 | 74 ## Form A and B into sets. |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
75 if (nargout > 1 || ! optsorted) |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
76 [a, ia] = unique (a, varargin{:}); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
77 [b, ib] = unique (b, varargin{:}); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
78 else |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
79 a = unique (a, varargin{:}); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
80 b = unique (b, varargin{:}); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
81 endif |
5825 | 82 |
83 if (isempty (a)) | |
84 c = b; | |
85 elseif (isempty (b)) | |
86 c = a; | |
87 else | |
88 ## Reject duplicates. | |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
89 if (by_rows) |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
90 na = rows (a); nb = rows (b); |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
91 [c, i] = sortrows ([a; b]); |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
92 n = rows (c); |
18081
42df174ec2ff
setxor.m: Fix bug when "rows" argument given (bug #40808).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
93 idx = find (all (c(1:n-1, :) == c(2:n, :), 2)); |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
94 if (optsorted) |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
95 if (! isempty (idx)) |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
96 c([idx, idx+1],:) = []; |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
97 i([idx, idx+1],:) = []; |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
98 endif |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
99 else |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
100 c = [a; b]; |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
101 c(i([idx, idx+1]), :) = []; |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
102 if (nargout > 1) |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
103 i([idx, idx+1]) = []; |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
104 ## FIXME: Is there a way to avoid a call to sort? |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
105 i = sort (i); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
106 endif |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
107 endif |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
108 else |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
109 na = numel (a); nb = numel (b); |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
110 [c, i] = sort ([a(:); b(:)]); |
9481
a3ae7abaf659
support cellstrs in setxor
Pieter Eendebak <pieter.eendebak@gmail.com>
parents:
9051
diff
changeset
|
111 if (iscell (c)) |
27296
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27294
diff
changeset
|
112 idx = find (strcmp (c(1:end-1), c(2:end))); |
9481
a3ae7abaf659
support cellstrs in setxor
Pieter Eendebak <pieter.eendebak@gmail.com>
parents:
9051
diff
changeset
|
113 else |
27296
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27294
diff
changeset
|
114 idx = find (c(1:end-1) == c(2:end)); |
9481
a3ae7abaf659
support cellstrs in setxor
Pieter Eendebak <pieter.eendebak@gmail.com>
parents:
9051
diff
changeset
|
115 endif |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
116 if (optsorted) |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
117 if (! isempty (idx)) |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
118 c([idx, idx+1]) = []; |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
119 i([idx, idx+1]) = []; |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
120 endif |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
121 else |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
122 c = [a(:); b(:)]; |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
123 c(i([idx, idx+1])) = []; |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
124 if (nargout > 1) |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
125 i([idx, idx+1]) = []; |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
126 ## FIXME: Is there a way to avoid a call to sort? |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
127 i = sort (i); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
128 endif |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
129 endif |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
130 |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
131 ## Adjust output orientation for Matlab compatibility |
19974
72ccbd36e23c
Return a column vector by default for Matlab compatibility (bug #44425, bug #44453).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
132 if (isrowvec) |
10549 | 133 c = c.'; |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
134 endif |
5825 | 135 endif |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
136 |
19157
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
137 if (nargout > 1) |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
138 ia = ia(i(i <= na)); |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
139 ib = ib(i(i > na) - na); |
27238
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
140 if (optlegacy && isrowvec) |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
141 ia = ia(:).'; |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
142 ib = ib(:).'; |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
143 endif |
19157
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
144 endif |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
145 endif |
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
146 |
5825 | 147 endfunction |
148 | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
149 |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
150 %!assert (setxor ([3,1,2], [4,3,2]), [1,4]) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14359
diff
changeset
|
151 %!assert (setxor ({'a'}, {'a', 'b'}), {'b'}) |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
152 %!assert (setxor ([5, NaN, NaN], [NaN, NaN, 5]), [NaN NaN NaN NaN]) |
18081
42df174ec2ff
setxor.m: Fix bug when "rows" argument given (bug #40808).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
153 |
7920
e56bb65186f6
improve set functions for Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
154 %!test |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
155 %! a = [3, 1, 4, 1, 5]; |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
156 %! b = [1; 2; 3; 4]; |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
157 %! [c, ia, ib] = setxor (a, b); |
19974
72ccbd36e23c
Return a column vector by default for Matlab compatibility (bug #44425, bug #44453).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
158 %! assert (c, [2; 5]); |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
159 %! assert (ia, [5]); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
160 %! assert (ib, [2]); |
9498
f7cc8f30f3b8
Added test for setxor
Pieter Eendebak <pieter.eendebak@gmail.com>
parents:
9481
diff
changeset
|
161 |
27296
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27294
diff
changeset
|
162 ## Test multi-dimensional arrays |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27294
diff
changeset
|
163 %!test |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27294
diff
changeset
|
164 %! a = rand (3,3,3); |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27294
diff
changeset
|
165 %! b = a; |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27294
diff
changeset
|
166 %! b(1,1,1) = 2; |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27294
diff
changeset
|
167 %! assert (intersect (a, b), sort (a(2:end)')); |
538468f901dd
Clean up BIST tests in set functions.
Rik <rik@octave.org>
parents:
27294
diff
changeset
|
168 |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
169 ## Test "rows" input |
18081
42df174ec2ff
setxor.m: Fix bug when "rows" argument given (bug #40808).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
170 %!test |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
171 %! a = [1 2; 4 5; 1 3]; |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
172 %! b = [1 1; 1 2; 4 5; 2 10]; |
18081
42df174ec2ff
setxor.m: Fix bug when "rows" argument given (bug #40808).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
173 %! [c, ia, ib] = setxor (a, b, "rows"); |
42df174ec2ff
setxor.m: Fix bug when "rows" argument given (bug #40808).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
174 %! assert (c, [1 1; 1 3; 2 10]); |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
175 %! assert (ia, [3]); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
176 %! assert (ib, [1; 4]); |
18081
42df174ec2ff
setxor.m: Fix bug when "rows" argument given (bug #40808).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
177 |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
178 ## Test "stable" sort order |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
179 %!test |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
180 %! a = [3, 1, 4, 1, 5]; |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
181 %! b = [1; 2; 3; 4]; |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
182 %! [c, ia, ib] = setxor (a, b, "stable"); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
183 %! assert (c, [5; 2]); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
184 %! assert (ia, [5]); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
185 %! assert (ib, [2]); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
186 |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
187 %!test |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
188 %! a = [1 2; 4 5; 1 3]; |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
189 %! b = [1 1; 1 2; 4 5; 2 10]; |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
190 %! [c, ia, ib] = setxor (a, b, "rows", "stable"); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
191 %! assert (c, [1 3; 1 1; 2 10]); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
192 %! assert (ia, [3]); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
193 %! assert (ib, [1; 4]); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
194 |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
195 ## Test various empty matrix inputs |
19157
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
196 %!assert (setxor (1, []), 1) |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
197 %!assert (setxor ([], 1), 1) |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
198 |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
199 %!test |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
200 %! [c, ia, ib] = setxor ([3 1], []); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
201 %! assert (c, [1 3]); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
202 %! assert (ia, [2; 1]); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
203 %! assert (ib, []); |
19157
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
204 %!test |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
205 %! [c, ia, ib] = setxor ([], [3 1]); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
206 %! assert (c, [1 3]); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
207 %! assert (ia, []); |
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
208 %! assert (ib, [2; 1]); |
19157
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
209 |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
210 %!test |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
211 %! a = [2 1; 4 3]; b = []; |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
212 %! [c, ia, ib] = setxor (a, b); |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
213 %! assert (c, [1; 2; 3; 4]); |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
214 %! assert (ia, [3; 1; 4; 2]); |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
215 %! assert (isempty (ib)); |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
216 |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
217 %!test |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
218 %! a = []; b = [2 1; 4 3]; |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
219 %! [c, ia, ib] = setxor (a, b); |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
220 %! assert (c, [1; 2; 3; 4]); |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
221 %! assert (isempty (ia)); |
d171e23cac81
setxor.m: Fix bug with empty set input and multiple outputs (bug #43140).
Julien Bect <julien.bect@supelec.fr>
parents:
19003
diff
changeset
|
222 %! assert (ib, [3; 1; 4; 2]); |
27294
aa4147476138
setxor.m: Add new option "stable" to control output ordering.
Rik <rik@octave.org>
parents:
27238
diff
changeset
|
223 |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
224 ## Test orientation of output |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
225 %!shared x,y |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
226 %! x = 1:3; |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
227 %! y = 2:5; |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
228 |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
229 %!assert (size (setxor (x, y)), [1 3]) |
19974
72ccbd36e23c
Return a column vector by default for Matlab compatibility (bug #44425, bug #44453).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
230 %!assert (size (setxor (x', y)), [3 1]) |
72ccbd36e23c
Return a column vector by default for Matlab compatibility (bug #44425, bug #44453).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
231 %!assert (size (setxor (x, y')), [3 1]) |
19003
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
232 %!assert (size (setxor (x', y')), [3 1]) |
d00f6b09258f
Overhaul functions in scripts/set directory.
Rik <rik@octave.org>
parents:
18081
diff
changeset
|
233 |
27238
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
234 ## Test "legacy" input |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
235 %!test |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
236 %! a = [5 1 3 3 3]; |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
237 %! b = [4 1 2 2]; |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
238 %! [c,ia,ib] = setxor (a,b); |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
239 %! assert (c, [2, 3, 4, 5]); |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
240 %! assert (ia, [3; 1]); |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
241 %! assert (ib, [3; 1]); |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
242 %! [c,ia,ib] = setxor (a,b, "legacy"); |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
243 %! assert (c, [2, 3, 4, 5]); |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
244 %! assert (ia, [5, 1]); |
177be3c01238
setxor.m: Accept a "legacy" flag for Matlab compatibility.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
245 %! assert (ib, [4, 1]); |