Mercurial > octave
annotate scripts/set/uniquetol.m @ 31120:4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Use standard form for error() messages and update input validation BIST tests
to pass.
* uniquetol.m: Use "real" instead of "non-complex" in documentation and in
error() messages. Update input validation BIST tests to pass with new
messages. Update documentation example so that text matches actual output
of Octave. Use isreal() rather than iscomplex() in input validation.
New variable "calc_indices" which indicates whether outputs ia, ic should
be calculated. Use "calc_indices" to reduce running unnecessary code.
In ByRows code, eliminate Iall variable and use J for the same purpose.
Eliminate linear search ("any (Iall == i)") with direct lookup ("if (J(i))").
Eliminate variables sumeq, ii. Introduce intermediate variable "Arow_i" for
clarity. Rename "equ" to "eq_rows" for clarity. Use '!' instead of '~'
for logical negation.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 05 Jul 2022 17:14:44 -0700 |
parents | df030ac26390 |
children | fd29c7a50a78 |
rev | line source |
---|---|
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
1 ######################################################################## |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
2 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30383
diff
changeset
|
3 ## Copyright (C) 2020-2022 The Octave Project Developers |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
4 ## |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
7 ## |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
8 ## This file is part of Octave. |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
9 ## |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
11 ## under the terms of the GNU General Public License as published by |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
13 ## (at your option) any later version. |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
14 ## |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
15 ## Octave is distributed in the hope that it will be useful, but |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
18 ## GNU General Public License for more details. |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
19 ## |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
21 ## along with Octave; see the file COPYING. If not, see |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
23 ## |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
24 ######################################################################## |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
25 |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
26 ## -*- texinfo -*- |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
27 ## @deftypefn {} {@var{c} =} uniquetol (@var{A}) |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
28 ## @deftypefnx {} {@var{c} =} uniquetol (@var{A}, @var{tol}) |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
29 ## @deftypefnx {} {@var{c} =} uniquetol (@dots{}, @var{property}, @var{value}) |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
30 ## @deftypefnx {} {[@var{c}, @var{ia}, @var{ic}] =} uniquetol (@dots{}) |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
31 ## Return the unique elements of @var{A} within tolerance @var{tol}. |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
32 ## |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
33 ## Two values, @var{x} and @var{y}, are within relative tolerance if |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
34 ## @code{abs (@var{x} - @var{y}) <= @var{tol} * max (abs (@var{A}(:)))}. |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
35 ## |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
36 ## The input @var{A} must be a real (non-complex) floating point type (double |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
37 ## or single). |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
38 ## |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
39 ## If @var{tol} is unspecified, the default tolerance is 1e-12 for double |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
40 ## precision input or 1e-6 for single precision input. |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
41 ## |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
42 ## The function may also be called with the following optional property/value |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
43 ## pairs. Property/value pairs must be passed after other input arguments: |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
44 ## |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
45 ## @table @asis |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
46 ## @item @qcode{"ByRows"} (default: @code{false}) |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
47 ## When true, return the unique rows of @var{A}. @var{A} must be a 2-D array |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
48 ## to use this option. For rows, the criteria for uniqueness is changed to |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
49 ## @code{all (abs (@var{x} - @var{y}) <= @var{tol}*max (abs (@var{A}),[],1))} |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
50 ## which compares each column component of a row against a column-specific |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
51 ## tolerance. |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
52 ## |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
53 ## @item @qcode{"DataScale"} |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
54 ## The tolerance test is changed to |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
55 ## @code{abs (@var{x} - @var{y}) <= @var{tol}*@var{DS}} where @var{DS} is a |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
56 ## scalar unless the property @qcode{"ByRows"} is true. In that case, @var{DS} |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
57 ## can either be a scalar or a vector with a length equal to the number of |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
58 ## columns in @var{A}. Using a value of @code{1.0} for @var{DS} will change |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
59 ## the tolerance from a relative one to an absolute tolerance. Using a value |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
60 ## of @code{Inf} will disable testing. |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
61 ## |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
62 ## @item @qcode{"OutputAllIndices"} (default: @code{false}) |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
63 ## When true, @var{ia} is a cell array (not a vector) that contains the indices |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
64 ## for @emph{all} elements in @var{A} that are within tolerance of a value in |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
65 ## @var{C}. That is, each cell in @var{ia} corresponds to a single unique |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
66 ## value in @var{C}, and the values in each cell correspond to locations in |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
67 ## @var{A}. |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
68 ## @end table |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
69 ## |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
70 ## The output @var{c} is a row vector if the input @var{A} is a row vector. |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
71 ## For all other cases, a column vector is returned. |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
72 ## |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
73 ## The optional output @var{ia} is a column index vector such that |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
74 ## @code{@var{c} = @var{A}(@var{ia})}. If the @qcode{"ByRows"} property is |
29312
875d799ab0b3
uniquetol.m: Fix texinfo syntax errors (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29311
diff
changeset
|
75 ## true, the condition is @code{@var{c} = @var{A}(@var{ia}, :)}. If the |
875d799ab0b3
uniquetol.m: Fix texinfo syntax errors (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29311
diff
changeset
|
76 ## @qcode{"OutputAllIndices"} property is true, then the values |
875d799ab0b3
uniquetol.m: Fix texinfo syntax errors (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29311
diff
changeset
|
77 ## @code{@var{A}(@var{ia}@{@var{i}@})} are all within tolerance of the unique |
875d799ab0b3
uniquetol.m: Fix texinfo syntax errors (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29311
diff
changeset
|
78 ## value @code{@var{c}(@var{i})}. |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
79 ## |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
80 ## The optional output @var{ic} is a column index vector such that |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
81 ## @code{@var{A} = @var{c}(@var{ic})} when @var{A} is a vector. When @var{A} |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
82 ## is a matrix, @code{@var{A}(:) = @var{c}(@var{ic})}. If the @qcode{"ByRows"} |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
83 ## property is true then @code{@var{A} = @var{c}(@var{ic},:)}. |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
84 ## |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
85 ## Example: small round-off errors require @code{uniquetol}, not @code{unique} |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
86 ## |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
87 ## @example |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
88 ## @group |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
89 ## x = [1:5]; |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
90 ## ## Inverse_Function (Function (x)) should return exactly x |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
91 ## y = exp (log (x)); |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
92 ## D = unique ([x, y]) |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
93 ## @result{} [1 2 3 3 4 5 5] |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
94 ## C = uniquetol ([x, y]) |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
95 ## @result{} [1 2 3 4 5] |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
96 ## @end group |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
97 ## @end example |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
98 ## |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
99 ## @seealso{unique, union, intersect, setdiff, setxor, ismember} |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
100 ## @end deftypefn |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
101 |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
102 function [c, ia, ic] = uniquetol (A, varargin) |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
103 |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
104 if (nargin < 1) |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
105 print_usage (); |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
106 endif |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
107 |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
108 if (! (isfloat (A) && isreal (A))) |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
109 error ("Octave:uniquetol:unsupported-type", |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
110 "uniquetol: A must be a real floating point array"); |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
111 endif |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
112 |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
113 if (nargin == 1 || ischar (varargin{1})) |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
114 tol = ifelse (isa (A, "double"), 1e-12, 1e-6); |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
115 else |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
116 tol = varargin{1}; |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
117 varargin(1) = []; |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
118 if (! (isfloat (tol) && isreal (tol) && isscalar (tol))) |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
119 error ("Octave:uniquetol:unsupported-type", |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
120 "uniquetol: TOL must be a real floating point scalar"); |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
121 endif |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
122 endif |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
123 |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
124 if (mod (numel (varargin), 2)) |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
125 error ("uniquetol: PROPERTY/VALUE arguments must occur in pairs"); |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
126 endif |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
127 |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
128 by_rows = false; |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
129 output_all_indices = false; |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
130 data_scale = []; |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
131 calc_indices = nargout > 1; |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
132 |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
133 for k = 1:2:numel (varargin) |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
134 if (! ischar (varargin{k})) |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
135 error ("uniquetol: PROPERTY must be a string"); |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
136 endif |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
137 |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
138 if (strcmpi (varargin{k}, "ByRows")) |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
139 by_rows = logical (varargin{k+1}); |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
140 if (by_rows && ndims (A) > 2) |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
141 error ('uniquetol: A must be a 2-D array when "ByRows" is true'); |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
142 endif |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
143 elseif (strcmpi (varargin{k}, "OutputAllIndices")) |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
144 output_all_indices = logical (varargin{k+1}) & calc_indices; |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
145 elseif (strcmpi (varargin{k}, "DataScale")) |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
146 data_scale = varargin{k+1}(:).'; |
30296
d6415c931759
uniquetol.m: Check for complex input (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29463
diff
changeset
|
147 if (! isfloat (data_scale) || iscomplex (data_scale) |
d6415c931759
uniquetol.m: Check for complex input (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29463
diff
changeset
|
148 || any (data_scale(:) < 0) || any (isnan (data_scale(:)))) |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
149 error ("uniquetol: DataScale must be a positive floating point scalar or vector, without NaNs"); |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
150 endif |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
151 cols_data_scale = columns (data_scale); |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
152 if (cols_data_scale != 1 && cols_data_scale != columns (A)) |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
153 error ("uniquetol: invalid DataScale size"); |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
154 endif |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
155 else |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
156 error ("uniquetol: unknown property '%s'", varargin{k}); |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
157 endif |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
158 endfor |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
159 |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
160 if (isempty (A)) |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
161 ## hack for Matlab empty input compatibility |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
162 sz_A = size (A); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
163 if (by_rows) |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
164 c = A; |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
165 sz_A(2) = 1; |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
166 ia = ones (sz_A); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
167 ic = ones (sz_A); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
168 else |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
169 c = ones (0, 1, class (A)); |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
170 if (sz_A(1) == 1) |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
171 c = c.'; |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
172 endif |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
173 ia = ones (0, 1); |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
174 ic = ones (0, 1); |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
175 endif |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
176 return; |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
177 endif |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
178 |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
179 if (isempty (data_scale)) |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
180 data_scale = max (abs (A(! isinf (A))(:))); |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
181 endif |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
182 |
29463
09767c20dec9
uniquetol.m: variable naming cleanup and addition of BIST test.
Rik <rik@octave.org>
parents:
29461
diff
changeset
|
183 tol *= data_scale; |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
184 |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
185 if (by_rows) |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
186 ## Start matrix in sorted order, retain sorting and inverting indices. |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
187 if (calc_indices) |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
188 [A, srtA] = sortrows (A); |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
189 [~, inv_srtA] = sort (srtA); |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
190 else |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
191 A = sortrows (A); |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
192 endif |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
193 |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
194 [nr, nc] = size (A); |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
195 I = zeros (nr, 1); |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
196 ia = {}; |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
197 J = zeros (nr, 1); |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
198 j = 1; |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
199 |
29463
09767c20dec9
uniquetol.m: variable naming cleanup and addition of BIST test.
Rik <rik@octave.org>
parents:
29461
diff
changeset
|
200 for i = 1:nr |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
201 if (J(i)) |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
202 continue; # row previously compared equal |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
203 endif |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
204 |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
205 Arow_i = A(i,:); |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
206 eq_rows = all (abs (A - Arow_i) <= tol, 2); |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
207 eq_rows(i,1) = eq_rows(i,1) || any (! isfinite (Arow_i), 2); |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
208 if (output_all_indices) |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
209 ia_tmp = find (eq_rows); |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
210 ia{end+1,1} = sort (srtA(ia_tmp)); |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
211 else |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
212 ia_tmp = find (eq_rows, 1); |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
213 endif |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
214 I(j) = ia_tmp(1); |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
215 J(eq_rows) = j; |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
216 j += 1; |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
217 endfor |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
218 |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
219 I = I(1:j-1); |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
220 c = A(I,:); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
221 |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
222 if (calc_indices) |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
223 if (! output_all_indices) |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
224 ia = srtA(I(1:j-1)); |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
225 endif |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
226 ic = J(inv_srtA); |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
227 endif |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
228 |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
229 else |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
230 isrowvec = isrow (A); |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
231 A = A(:); |
29463
09767c20dec9
uniquetol.m: variable naming cleanup and addition of BIST test.
Rik <rik@octave.org>
parents:
29461
diff
changeset
|
232 nr = rows (A); |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
233 isnanA = isnan (A); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
234 anyisnanA = any (isnanA); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
235 [sortA, sAi] = sort (A); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
236 diffsortA = diff (sortA); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
237 isinfsortA = isinf (sortA); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
238 isnansortA = isnan (sortA); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
239 numnan = sum (isnansortA); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
240 if (any (isinfsortA)) |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
241 sAnin = sortA(! (isinfsortA | isnansortA)); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
242 diffsortA(isinf (diffsortA)) = abs (sAnin(end) - sAnin(1)) + 10; |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
243 endif |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
244 csdx = cumsum (diffsortA); |
29463
09767c20dec9
uniquetol.m: variable naming cleanup and addition of BIST test.
Rik <rik@octave.org>
parents:
29461
diff
changeset
|
245 ue = [true; diff([0; csdx-mod(csdx,tol)]) > eps(max(csdx))]; |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
246 ueold = NaN; |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
247 while (any (ueold != ue)) |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
248 ueold = ue; |
29463
09767c20dec9
uniquetol.m: variable naming cleanup and addition of BIST test.
Rik <rik@octave.org>
parents:
29461
diff
changeset
|
249 belowtol = [false; diff(sortA(ue)) < tol]; |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
250 if (any (belowtol)) |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
251 needstomove = find (ue)(belowtol); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
252 ue(needstomove) = false; |
29463
09767c20dec9
uniquetol.m: variable naming cleanup and addition of BIST test.
Rik <rik@octave.org>
parents:
29461
diff
changeset
|
253 needstomove(needstomove >= nr-numnan) = []; |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
254 ue(needstomove+1) = true; |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
255 endif |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
256 endwhile |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
257 c = sortA(ue); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
258 [~, sortsAi] = sort (sAi); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
259 cumsumue = cumsum (ue); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
260 ic = cumsumue(sortsAi); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
261 if (anyisnanA) |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
262 findisnanA = find (isnanA); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
263 else |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
264 findisnanA = []; |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
265 endif |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
266 if (output_all_indices) |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
267 nu = cumsumue(end); |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
268 ia = cell (nu, 1); |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
269 for k = 1:nu |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
270 ia{k} = setdiff (sAi(cumsumue==k), findisnanA); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
271 endfor |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
272 else |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
273 ia = sAi(ue); |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
274 endif |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
275 |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
276 if (anyisnanA) |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
277 rowsc1 = [1:sum(isnanA(:))]'; |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
278 if (! all (isnanA)) |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
279 rowsc1 += rows (c); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
280 endif |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
281 c(rowsc1) = NaN; |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
282 ic(isnanA) = rowsc1; |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
283 if (output_all_indices) |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
284 ia(rowsc1) = num2cell (findisnanA); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
285 else |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
286 ia(rowsc1) = findisnanA; |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
287 endif |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
288 |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
289 ## if numel (c) was 1, appending NaNs creates a row vector instead of |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
290 ## expected column vector. |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
291 if (isrow (c)) |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
292 c = c.'; |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
293 endif |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
294 endif |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
295 |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
296 ## Matlab compatibility: Outputs are column vectors unless the input |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
297 ## is a row vector, in which case the output c is also a row vector. |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
298 ## ia and ic are always column vectors. (verified Matlab 2022a) |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
299 if (isrowvec) |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
300 c = c.'; |
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
301 endif |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
302 endif |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
303 |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
304 endfunction |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
305 |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
306 |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
307 %!assert (uniquetol ([1 1 2; 1 2 1; 1 1 2+10*eps]), [1;2]) |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
308 %!assert (uniquetol ([1 1 2; 1 0 1; 1 1 2+10*eps], "byrows", true), |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
309 %! [1 0 1; 1 1 2]) |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
310 %!assert (uniquetol ([1]), [1]) |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
311 %!assert (uniquetol ([2, 1]), [1, 2]); |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
312 %!assert (uniquetol ([1; 2]), [1; 2]) |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
313 %!assert (uniquetol ([-Inf, 1, NaN, Inf, NaN, Inf]), [-Inf, 1, Inf, NaN, NaN]); |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
314 %!assert (uniquetol ([1,2,2,3,2,4], "byrows", true), [1,2,2,3,2,4]) |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
315 %!assert (uniquetol ([1,2,2,3,2,4]), [1,2,3,4]) |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
316 %!assert (uniquetol ([1,2,2,3,2,4].', "byrows", true), [1;2;3;4]) |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
317 %!assert (uniquetol (sparse ([2,0;2,0])), sparse ([0;2])) |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
318 %!assert (uniquetol (sparse ([1,2;2,3])), sparse ([1;2;3])) |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
319 %!assert (uniquetol (single ([1,2,2,3,2,4]), "byrows", true), |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
320 %! single ([1,2,2,3,2,4])) |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
321 %!assert (uniquetol (single ([1,2,2,3,2,4])), single ([1,2,3,4])) |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
322 %!assert (uniquetol (single ([1,2,2,3,2,4].'), "byrows", true), |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
323 %! single ([1;2;3;4])) |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
324 |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
325 ## Test 2D array sorting |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
326 %!test |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
327 %! a = [magic(3); 2 * magic(3)]; |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
328 %! assert (uniquetol (a), [1:10,12,14,16,18]') |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
329 %! assert (uniquetol (a, "byrows", true), sortrows (a)) |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
330 |
29463
09767c20dec9
uniquetol.m: variable naming cleanup and addition of BIST test.
Rik <rik@octave.org>
parents:
29461
diff
changeset
|
331 ## Matlab compatibility of output |
09767c20dec9
uniquetol.m: variable naming cleanup and addition of BIST test.
Rik <rik@octave.org>
parents:
29461
diff
changeset
|
332 %!test |
09767c20dec9
uniquetol.m: variable naming cleanup and addition of BIST test.
Rik <rik@octave.org>
parents:
29461
diff
changeset
|
333 %! x = 1:0.045:3; |
09767c20dec9
uniquetol.m: variable naming cleanup and addition of BIST test.
Rik <rik@octave.org>
parents:
29461
diff
changeset
|
334 %! y = uniquetol (x, 0.1, "datascale", 1); |
09767c20dec9
uniquetol.m: variable naming cleanup and addition of BIST test.
Rik <rik@octave.org>
parents:
29461
diff
changeset
|
335 %! assert (y(1:4), [1, 1.135, 1.27, 1.405]); |
09767c20dec9
uniquetol.m: variable naming cleanup and addition of BIST test.
Rik <rik@octave.org>
parents:
29461
diff
changeset
|
336 |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
337 ## Test index vector return arguments |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
338 %!test |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
339 %! [c, ia, ic] = uniquetol ([1,1,2,3,3,3,4]); |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
340 %! assert (c, [1,2,3,4]); |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
341 %! assert (ia, [1;3;4;7]); |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
342 %! assert (ic, [1;1;2;3;3;3;4]); |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
343 |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
344 ## Test index vector return arguments with "ByRows" |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
345 %!test |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
346 %! A = [2, 3, 4; 2, 3, 4]; |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
347 %! [c, ia, ic] = uniquetol (A, "byrows", true); |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
348 %! assert (c, [2, 3, 4]); |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
349 %! assert (ia, 1); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
350 %! assert (ic, [1;1]); |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
351 |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
352 %!test |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
353 %! x = (2:7)'*pi; |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
354 %! y = exp (log (x)); |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
355 %! C = uniquetol ([x; y]); |
29461
df641f946202
uniquetol.m: Improve performance when "byrows" is false (bug #59850).
Steven <steven.waldrip@gmail.com>
parents:
29359
diff
changeset
|
356 %! assert (C, x, 1e-12); |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
357 |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
358 ## Test "ByRows" Property |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
359 %!test |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
360 %! A = [0.06, 0.21, 0.38; 0.38, 0.21, 0.39; 0.54, 0.56, 0.41; 0.46, 0.52, 0.95]; |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
361 %! B = log (exp (A)); |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
362 %! C = uniquetol ([A; B], "ByRows", true); |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
363 %! assert (C, sortrows(A), 10*eps); |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
364 |
29311
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
365 ## Test "DataScale" Property |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
366 %!test |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
367 %! x = 10^11; |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
368 %! C = uniquetol ([x, exp(log(x))], 1e-6, "DataScale", 1); |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
369 %! assert (C, [x, exp(log(x))]); |
2d26113ddf57
uniquetol.m: Update documentation and BIST tests (bug #59850).
Rik <rik@octave.org>
parents:
29309
diff
changeset
|
370 |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
371 ## Test "OutputAllIndices" Property |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
372 %!test |
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
373 %! A = [.1 .2 .3 10]; |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
374 %! [C, ia, ic] = uniquetol (A, .1, "OutputAllIndices", true); |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
375 %! assert (C, [.1, 10]); |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
376 %! assert (ia, {(1:3)'; 4}); |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
377 %! assert (ic, [1; 1; 1; 2]); |
29308
f3272029d42c
uniquetol.m: Add new function (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
diff
changeset
|
378 |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
379 ## Test NaN inputs |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
380 %!assert (uniquetol (NaN), NaN) |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
381 %!assert (uniquetol ([NaN NaN]), [NaN NaN]) |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
382 %!assert (uniquetol ([NaN NaN]'), [NaN NaN]') |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
383 %!assert (uniquetol (NaN(2,2)), NaN(4,1)) |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
384 |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
385 %!test |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
386 %! a = [magic(3); 2 * magic(3)]; |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
387 %! a(4:5) = NaN; |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
388 %! [c, ia, ic] = uniquetol (a); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
389 %! assert (c, [1:10,12,14,18, NaN, NaN]'); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
390 %! assert (ia, [7,10,2,3,8,13,14,1,9,11,16,17,12,4,5]'); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
391 %! assert (ic, [8,3,4,14,15,8,1,5,9,2,10,13,6,7,2,11,12,4]'); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
392 %! [c, ia, ic] = uniquetol (single (a)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
393 %! assert (class (c), "single"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
394 %! assert (class (ia), "double"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
395 %! assert (class (ic), "double"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
396 %! [c, ia, ic] = uniquetol (a, "ByRows", true); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
397 %! assert (c, sortrows (a)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
398 %! assert (ia, [2,3,1,6,4,5]'); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
399 %! assert (ic, [3,1,2,5,6,4]'); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
400 %! [c, ia, ic] = uniquetol (single (a), "ByRows", true); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
401 %! assert (class (c), "single"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
402 %! assert (class (ia), "double"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
403 %! assert (class (ic), "double"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
404 %! [c, ia, ic] = uniquetol (a, "OutputAllIndices", true); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
405 %! assert (ia, {7;[10;15];2;[3;18];8;13;14;[1;6];9;11;16;17;12;4;5}); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
406 %! [c, ia, ic] = uniquetol (single (a), "OutputAllIndices", true); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
407 %! assert (class (c), "single"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
408 %! assert (class (ia{1}), "double"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
409 %! assert (class (ic), "double"); |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
410 %! [c, ia, ic] = uniquetol (a, "OutputAllIndices", true, "ByRows", true); |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
411 %! assert (ia, {2;3;1;6;4;5}); |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
412 %! [c, ia, ic] = uniquetol (single (a), |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
413 %! "OutputAllIndices", true, "ByRows", true); |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
414 %! assert (class (c), "single"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
415 %! assert (class (ia{1}), "double"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
416 %! assert (class (ic), "double"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
417 |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
418 ## Test empty input compatibility |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
419 %!test |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
420 %! [c, ia, ic] = uniquetol ([]); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
421 %! assert (c, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
422 %! assert (ia, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
423 %! assert (ic, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
424 %!test |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
425 %! [c, ia, ic] = uniquetol ([], "byrows", true); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
426 %! assert (c, []); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
427 %! assert (ia, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
428 %! assert (ic, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
429 %!test |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
430 %! [c, ia, ic] = uniquetol (ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
431 %! assert (c, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
432 %! assert (ia, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
433 %! assert (ic, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
434 %!test |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
435 %! [c, ia, ic] = uniquetol (ones (0,1), "byrows", true); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
436 %! assert (c, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
437 %! assert (ia, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
438 %! assert (ic, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
439 %!test |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
440 %! [c, ia, ic] = uniquetol (ones (1,0)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
441 %! assert (c, ones (1,0)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
442 %! assert (ia, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
443 %! assert (ic, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
444 %!test |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
445 %! [c, ia, ic] = uniquetol (ones (1,0), "byrows", true); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
446 %! assert (c, ones (1,0)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
447 %! assert (ia, 1); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
448 %! assert (ic, 1); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
449 %!test |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
450 %! [c, ia, ic] = uniquetol (ones (1,0,2)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
451 %! assert (c, ones (1,0)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
452 %! assert (ia, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
453 %! assert (ic, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
454 %!test |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
455 %! [c, ia, ic] = uniquetol (ones (0,1,2)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
456 %! assert (c, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
457 %! assert (ia, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
458 %! assert (ic, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
459 %!test |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
460 %! [c, ia, ic] = uniquetol (ones (1,2,0)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
461 %! assert (c, ones (1,0)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
462 %! assert (ia, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
463 %! assert (ic, ones (0,1)); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
464 %!test |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
465 %! [c, ia, ic] = uniquetol (single ([])); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
466 %! assert (class (c), "single"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
467 %! assert (class (ia), "double"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
468 %! assert (class (ic), "double"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
469 %!test |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
470 %! [c, ia, ic] = uniquetol (single ([]), "byrows", true); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
471 %! assert (class (c), "single"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
472 %! assert (class (ia), "double"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
473 %! assert (class (ic), "double"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
474 %!test |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
475 %! [c, ia, ic] = uniquetol (single ([]), "OutputAllIndices", true); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
476 %! assert (class (c), "single"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
477 %! assert (class (ia), "double"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
478 %! assert (class (ic), "double"); |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
479 |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
480 |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
481 ## Test input validation |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
482 %!error <Invalid call> uniquetol () |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
483 %!error <A must be a real floating point array> uniquetol (int8 (1)) |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
484 %!error <A must be a real floating point array> uniquetol (1i) |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
485 %!error <TOL must be a real floating point scalar> uniquetol (1, int8 (1)) |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
486 %!error <TOL must be a real floating point scalar> uniquetol (1, [1, 2]) |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
487 %!error <TOL must be a real floating point scalar> uniquetol (1, 1i) |
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
488 %!error <arguments must occur in pairs> uniquetol (1, 2, "byrows") |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
489 %!error <PROPERTY must be a string> uniquetol (1, 2, 3, "bar") |
30383
8afdeac24ba4
maint: Use space after function name and before opening parenthesis.
Rik <rik@octave.org>
parents:
30296
diff
changeset
|
490 %!error <A must be a 2-D array> uniquetol (ones (2,2,2), "byrows", true) |
31119
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
491 %!error <A must be a 2-D array> uniquetol (ones (0,1,2), "byrows", true) |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
492 %!error <A must be a 2-D array> uniquetol (ones (1,0,2), "byrows", true) |
df030ac26390
uniquetol.m: improve matlab compatibility and add byrows sorting (bug #59850)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents:
30564
diff
changeset
|
493 %!error <A must be a 2-D array> uniquetol (ones (1,2,0), "byrows", true) |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
494 %!error <DataScale must be a .* floating point> uniquetol (1, "DataScale", '1') |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
495 %!error <DataScale must be .* positive> uniquetol (1, "DataScale", 1i) |
30296
d6415c931759
uniquetol.m: Check for complex input (bug #59850).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29463
diff
changeset
|
496 %!error <DataScale must be .* positive> uniquetol (1, "DataScale", -1) |
31120
4581402b1c5b
uniquetol.m: Simplify code for "ByRows" option (bug #59850).
Rik <rik@octave.org>
parents:
31119
diff
changeset
|
497 %!error <DataScale must be .* without NaNs> uniquetol (1, "DataScale", NaN) |
29309
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
498 %!error <invalid DataScale size> uniquetol (1, "DataScale", [1 2]) |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
499 %!error <unknown property 'foo'> uniquetol (1, "foo", "bar") |
83fe13ca9ce3
uniquetol.m: Update to use more Octave conventions (bug #59850).
Rik <rik@octave.org>
parents:
29308
diff
changeset
|
500 %!error <unknown property 'foo'> uniquetol (1, 2, "foo", "bar") |