Mercurial > octave
annotate scripts/general/isequal.m @ 30558:83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
* isplaying.m, isrecording.m, isequal.m, isequaln.m, iscolormap.m,
is_valid_file_id.m, isdir.m, isstr.m, isbanded.m, isdefinite.m, isdiag.m,
ishermitian.m, issymmetric.m, istril.m, istriu.m, isdeployed.m, isfolder.m,
ismac.m, ismethod.m, ispc.m, isunix.m, isaxes.m, isfigure.m, isgraphics.m,
ishandle.m, ishold.m, ispref.m, isprime.m, isletter.m, isstring.m, isstrprop.m,
is_leap_year.m:
Use TF for output variable in documentation for isXXX functions.
Change variable name in code function prototype to match documentation.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 27 Dec 2021 16:07:08 -0800 |
parents | 7854d5752dd2 |
children | 83f9f8bda883 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
3 ## Copyright (C) 2000-2021 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
5178 | 7 ## |
5181 | 8 ## This file is part of Octave. |
5178 | 9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24326
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
7016 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24326
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
5181 | 14 ## |
7016 | 15 ## Octave is distributed in the hope that it will be useful, but |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
5178 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24326
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
5178 | 25 |
5182 | 26 ## -*- texinfo -*- |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
27 ## @deftypefn {} {@var{tf} =} isequal (@var{x1}, @var{x2}, @dots{}) |
5550 | 28 ## Return true if all of @var{x1}, @var{x2}, @dots{} are equal. |
16935
a7b2fc7fe1a9
binocdf.m: Reverse calling convention to betaincinv to preserve accuracy when p =~ 1.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
29 ## @seealso{isequaln} |
5182 | 30 ## @end deftypefn |
5178 | 31 |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
32 ## Algorithm: |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
33 ## |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
34 ## 1. Verify the class of x. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
35 ## a. All objects are of the same class |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
36 ## b. All objects are of a generic "numeric" class which includes |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
37 ## numeric, logical, and character arrays |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
38 ## 2. Verify size of all objects match. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
39 ## 3. Convert objects to struct, and then compare as stated below. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
40 ## 4. For each argument after x, compare it for equality with x: |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
41 ## a. char compare each member with strcmp |
24970
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
42 ## b. numeric compare each member with '==' with sparsity regarded |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
43 ## c. struct compare number of fieldnames, value of fieldnames, |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
44 ## and then each field with isequal (recursive) |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
45 ## d. cellstr compare each cellstr member with strcmp |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
46 ## e. cell compare each member with isequal (recursive) |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
47 ## f. fcn_handle compare using overloaded "eq" operator |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
48 |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
49 function tf = isequal (x, varargin) |
5181 | 50 |
12604
132c89bb44e3
maint: Refactor general/isXXX.m scripts to put input validation first.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
51 if (nargin < 2) |
6046 | 52 print_usage (); |
5550 | 53 endif |
5181 | 54 |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
55 nvarargin = nargin - 1; |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
56 two_args = (nvarargin == 1); # Optimization for base case of just 2 args |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
57 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
58 if (two_args) |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
59 y = varargin{1}; # alias y to second input for comparison |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
60 endif |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
61 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
62 ############################################################ |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
63 ## Generic tests for equality |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
64 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
65 ## All arguments must either be of the same class, |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
66 ## or they must be "numeric" values. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
67 if (two_args) |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
68 tf = (strcmp (class (x), class (y)) |
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
69 || ((isreal (x) || iscomplex (x)) && (isreal (y) || iscomplex (y)))); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
70 else |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
71 tf = (all (cellfun ("isclass", varargin, class (x))) |
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
72 || ((isreal (x) || iscomplex (x)) |
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
73 && all (cellfun ("isreal", varargin) |
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
74 | cellfun ("isnumeric", varargin)))); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
75 endif |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
76 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
77 ## Test that everything is the same size (which also tests dimensions) |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
78 if (tf) |
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
79 tf = size_equal (x, varargin{:}); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
80 endif |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
81 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
82 ## From here on, compare any objects as if they were structures. |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
83 if (tf && isobject (x)) |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
84 ## Locally suppress class-to-struct warning. We know what we are doing. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
85 warning ("off", "Octave:classdef-to-struct", "local"); |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
86 x = builtin ("struct", x); |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
87 if (two_args) |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
88 clear y; # break link to existing variable |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
89 varargin(1) = builtin ("struct", varargin{1}); |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
90 y = varargin{1}; # re-alias y to second input |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
91 else |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
92 for i = 1:nvarargin |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
93 varargin(i) = builtin ("struct", varargin{i}); |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
94 endfor |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
95 endif |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
96 endif |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
97 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
98 ############################################################ |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
99 ## Check individual classes. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
100 |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
101 if (tf) |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
102 if (two_args) |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
103 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
104 if (ischar (x) && ischar (y)) |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
105 ## char type. Optimization, strcmp is ~35% faster than '==' operator. |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
106 tf = strcmp (x, y); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
107 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
108 elseif (isreal (x) || iscomplex (x)) |
24970
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
109 if (issparse (x)) |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
110 ## sparse types. |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
111 [xi, xj, xv] = find (x); |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
112 [yi, yj, yv] = find (y); |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
113 tf = (length (xi) == length (yi)) && all (xi == yi) ... |
24970
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
114 && all (xj == yj) && all (xv == yv); |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
115 else |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
116 ## general "numeric" type. Use '==' operator. |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
117 m = (x == y); |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
118 tf = all (m(:)); |
24970
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
119 endif |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
120 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
121 elseif (isstruct (x)) |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
122 ## struct type. Compare # of fields, fieldnames, then field values. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
123 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
124 ## Test number of fields are equal. |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
125 tf = (numfields (x) == numfields (y)); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
126 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
127 ## Test that all the field names are equal. |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
128 if (tf) |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
129 s_fnm_x = sort (fieldnames (x)); |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
130 tf = all (strcmp (s_fnm_x, sort (fieldnames (y)))); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
131 endif |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
132 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
133 ## Test that all field values are equal. Slow because of recursion. |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
134 if (tf) |
24326
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
135 if (isscalar (x)) |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
136 for fldnm = s_fnm_x.' |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
137 tf = isequal (x.(fldnm{1}), y.(fldnm{1})); |
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
138 if (! tf) |
24326
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
139 break; |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
140 endif |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
141 endfor |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
142 else |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
143 ## struct arrays have to have the contents of each field wrapped |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
144 ## in a cell since it expands to a collection of values. |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
145 for fldnm = s_fnm_x.' |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
146 tf = isequal ({x.(fldnm{1})}, {y.(fldnm{1})}); |
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
147 if (! tf) |
24326
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
148 break; |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
149 endif |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
150 endfor |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
151 endif |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
152 endif |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
153 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
154 elseif (iscellstr (x) && iscellstr (y)) |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
155 ## cellstr type. Optimization over cell type by using strcmp. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
156 ## FIXME: It would be faster to use strcmp on whole cellstr arrays, |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
157 ## but bug #51412 needs to be fixed. Instead, time/space trade-off. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
158 ## Convert to char (space) for faster processing with strcmp (time). |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
159 tf = strcmp (char (x), char (y)); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
160 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
161 elseif (iscell (x)) |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
162 ## cell type. Check that each element of a cell is equal. Slow. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
163 n = numel (x); |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
164 idx = 1; |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
165 while (tf && idx <= n) |
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
166 tf = isequal (x{idx}, y{idx}); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
167 idx += 1; |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
168 endwhile |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
169 |
25803
23483673ba43
Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
170 elseif (is_function_handle (x)) |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
171 ## function type. Use '==' operator which is overloaded. |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
172 tf = (x == y); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
173 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
174 else |
24634
ab2321d4ba03
maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
175 error ("isequal: Impossible to reach code. File a bug report."); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
176 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
177 endif |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
178 |
28943
e3a337a57588
maint: Use only one '#' character for comments that trail code.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
179 else # More than two args. This is going to be slower in general. |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
180 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
181 if (ischar (x) && all (cellfun ("isclass", varargin, "char"))) |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
182 ## char type. Optimization, strcmp is ~35% faster than '==' operator. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
183 idx = 1; |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
184 while (tf && idx <= nvarargin) |
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
185 tf = strcmp (x, varargin{idx}); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
186 idx += 1; |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
187 endwhile |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
188 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
189 elseif (isreal (x) || iscomplex (x)) |
24970
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
190 |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
191 if (issparse (x)) |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
192 ## sparse types. |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
193 |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
194 idx = 1; |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
195 [xi, xj, xv] = find (x); |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
196 while (tf && idx <= nvarargin) |
24970
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
197 y = varargin{idx}; |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
198 [yi, yj, yv] = find (y); |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
199 tf = (length (xi) == length (yi)) && all (xi == yi) ... |
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
200 && all (xj == yj) && all (xv == yv); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
201 |
24970
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
202 idx += 1; |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
203 endwhile |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
204 |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
205 else |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
206 ## general "numeric" type. Use '==' operator. |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
207 |
24970
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
208 idx = 1; |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
209 while (tf && idx <= nvarargin) |
24970
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
210 y = varargin{idx}; |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
211 m = (x == y); |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
212 tf = all (m(:)); |
24970
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
213 |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
214 idx += 1; |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
215 endwhile |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
216 |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
217 endif |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
218 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
219 elseif (isstruct (x)) |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
220 ## struct type. Compare # of fields, fieldnames, then field values. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
221 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
222 ## Test number of fields are equal. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
223 fnm_x = fieldnames (x); |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
224 n = numel (fnm_x); |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
225 fnm_v = cellfun ("fieldnames", varargin, "uniformoutput", false); |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
226 tf = all (n == cellfun ("numel", fnm_v)); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
227 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
228 ## Test that all the field names are equal. |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
229 if (tf) |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
230 fnm_x = sort (fnm_x); |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
231 idx = 1; |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
232 while (tf && idx <= nvarargin) |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
233 ## Allow the fieldnames to be in a different order. |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
234 tf = all (strcmp (fnm_x, sort (fnm_v{idx}))); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
235 idx += 1; |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
236 endwhile |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
237 endif |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
238 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
239 ## Test that all field values are equal. Slow because of recursion. |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
240 if (tf) |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
241 args = cell (1, 1 + nvarargin); |
24326
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
242 if (isscalar (x)) |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
243 for fldnm = fnm_x.' |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
244 args{1} = x.(fldnm{1}); |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
245 for argn = 1:nvarargin |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
246 args{argn+1} = varargin{argn}.(fldnm{1}); |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
247 endfor |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
248 |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
249 tf = isequal (args{:}); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
250 |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
251 if (! tf) |
24326
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
252 break; |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
253 endif |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
254 endfor |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
255 else |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
256 ## struct arrays have to have the contents of each field wrapped |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
257 ## in a cell since it expands to a collection of values. |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
258 for fldnm = fnm_x.' |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
259 args{1} = { x.(fldnm{1}) }; |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
260 for argn = 1:nvarargin |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
261 args{argn+1} = { varargin{argn}.(fldnm{1}) }; |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
262 endfor |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
263 |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
264 tf = isequal (args{:}); |
24326
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
265 |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
266 if (! tf) |
24326
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
267 break; |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
268 endif |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
269 endfor |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
270 endif |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
271 endif |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
272 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
273 elseif (iscellstr (x) && all (cellfun (@iscellstr, varargin))) |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
274 ## cellstr type. Optimization over cell type by using strcmp. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
275 ## FIXME: It would be faster to use strcmp on whole cellstr arrays, |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
276 ## but bug #51412 needs to be fixed. Instead, time/space trade-off. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
277 ## Convert to char (space) for faster processing with strcmp (time). |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
278 idx = 1; |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
279 x = char (x); |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
280 while (tf && idx <= nvarargin) |
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
281 tf = strcmp (x, char (varargin{idx})); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
282 idx += 1; |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
283 endwhile |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
284 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
285 elseif (iscell (x)) |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
286 ## cell type. Check that each element of a cell is equal. Slow. |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
287 n = numel (x); |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
288 args = cell (1, 1 + nvarargin); |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
289 idx = 1; |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
290 while (tf && idx <= n) |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
291 args(1) = x{idx}; |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
292 args(2:end) = [cellindexmat(varargin, idx){:}]; |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
293 |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
294 tf = isequal (args{:}); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
295 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
296 idx += 1; |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
297 endwhile |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
298 |
25803
23483673ba43
Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
299 elseif (is_function_handle (x)) |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
300 ## function type. Use '==' operator which is overloaded. |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
301 tf = all (cellfun ("eq", {x}, varargin)); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
302 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
303 else |
24634
ab2321d4ba03
maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
304 error ("isequal: Impossible to reach code. File a bug report."); |
24309
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
305 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
306 endif |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
307 |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
308 endif |
1262d7c4712e
Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents:
24308
diff
changeset
|
309 endif |
12604
132c89bb44e3
maint: Refactor general/isXXX.m scripts to put input validation first.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
310 |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
311 tf = full (tf); # Always return full logical value for Matlab compatibility. |
24312
9d25e88d83f6
isequal.m, isequaln.m: Return a full, non-sparse, logical value for compatibility.
Rik <rik@octave.org>
parents:
24309
diff
changeset
|
312 |
5178 | 313 endfunction |
5549 | 314 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
315 |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
316 ## test empty input |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
317 %!assert (isequal ([], []), true) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
318 %!assert (isequal ([], 1), false) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
319 %!assert (isequal ([], [], 1), false) |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
320 %!assert (isequal ([], 1, []), false) |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
321 %!assert (isequal (1, [], []), false) |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
322 |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
323 ## test size and shape |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
324 %!assert (isequal ([1,2,3,4], [1,2,3,4]), true) |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
325 %!assert (isequal ([1;2;3;4], [1;2;3;4]), true) |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
326 %!assert (isequal ([1,2,3,4], [1;2;3;4]), false) |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
327 %!assert (isequal ([1,2,3,4], [1,2;3,4]), false) |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
328 %!assert (isequal ([1,2,3,4], [1,3;2,4]), false) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
329 %!assert (isequal ([1,2,3,4], [1,2,3,4], [1,2,3,4]), true) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
330 %!assert (isequal ([1;2;3;4], [1;2;3;4], [1;2;3;4]), true) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
331 %!assert (isequal ([1,2,3,4], [1,2,3,4], [1;2;3;4]), false) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
332 %!assert (isequal ([1,2,3,4], [1,2,3,4], [1,2;3,4]), false) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
333 %!assert (isequal ([1,2,3,4], [1,2,3,4], [1,3;2,4]), false) |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
334 |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
335 ## General tests |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
336 %!test |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
337 %! A = 1:8; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
338 %! B = reshape (A, 2, 2, 2); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
339 %! assert (isequal (A, B), false); |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
340 %! assert (isequal (A, A, B), false); |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
341 %!test |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
342 %! A = reshape (1:8, 2, 2, 2); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
343 %! B = A; |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
344 %! assert (isequal (A, B), true); |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
345 %! assert (isequal (A, A, B), true); |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
346 %!test |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
347 %! A = reshape (1:8, 2, 4); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
348 %! B = reshape (A, 2, 2, 2); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
349 %! assert (isequal (A, B), false); |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
350 %! assert (isequal (A, A, B), false); |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
351 |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
352 ## test characters and strings |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
353 %!assert (isequal ('a', "a"), true) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
354 %!assert (isequal ('a', 'a', "a"), true) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
355 %!assert (isequal ("abab", ["a", "b", "a", "b"]), true) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
356 %!assert (isequal ("abab", "abab", ["a", "b", "a", "b"]), true) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
357 %!assert (isequal (["a","b","c","d"], ["a","b","c","d"]), true) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
358 %!assert (isequal (["a","b","c","d"], ["a","b","c","d"], ["a","b","c","d"]), |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
359 %! true) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
360 %!assert (isequal (["test ";"strings"], ["test ";"strings"]), true) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
361 %!assert (isequal (["test ";"strings"], ["test ";"strings"], |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
362 %! ["test ";"strings"]), true) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
363 %!assert (isequal (["a","b","c","d"], ["a";"b";"c";"d"]), false) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
364 %!assert (isequal (["a","b","c","d"], ["a","b","c","d"], ["a";"b";"c";"d"]), |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
365 %! false) |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
366 |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
367 ## test all numeric built-in primitives |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
368 %!assert (isequal (false, 0)) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
369 %!assert (isequal (char (0), 0)) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
370 %!assert (isequal (false, logical (0), char (0), |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
371 %! int8 (0), int16 (0), int32 (0), int64 (0), |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
372 %! uint8 (0), uint16 (0), uint32 (0), uint64 (0), |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
373 %! double (0), single (0), |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
374 %! double (complex (0,0)), single (complex (0,0)), |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
375 %! sparse (false), sparse (logical (0)), |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
376 %! sparse (double (0)), sparse (single (0)), |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
377 %! sparse (double (complex (0,0))), |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
378 %! sparse (single (complex (0,0)))), |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
379 %! true) |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18786
diff
changeset
|
380 %!assert (isequal (true, logical (1), char (1), |
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18786
diff
changeset
|
381 %! int8 (1), int16 (1), int32 (1), int64 (1), |
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18786
diff
changeset
|
382 %! uint8 (1), uint16 (1), uint32 (1), uint64 (1), |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
383 %! double (1), single (1), |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
384 %! double (complex (1,0)), single (complex (1,0)), |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
385 %! sparse (true), sparse (logical (1)), |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
386 %! sparse (double (1)), sparse (single (1)), |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
387 %! sparse (double (complex (1,0))), |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
388 %! sparse (single (complex (1,0)))), |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
389 %! true) |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
390 |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
391 ## test structures |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
392 %!assert (isequal (struct ([]), struct ([])), true) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
393 %!assert (isequal (struct ([]), struct ([]), struct ([])), true) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
394 %!assert (isequal (struct ("a",1), struct ("a",1)), true) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
395 %!assert (isequal (struct ("a",1), struct ("a",1), struct ("a",1)), true) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
396 %!assert (isequal (struct ("a",1), struct ("a",2)), false) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
397 %!assert (isequal (struct ("a",1), struct ("a",1), struct ("a",2)), false) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
398 %!assert (isequal (struct ("a",1), struct ("a",1,"b",2)), false) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
399 %!assert (isequal (struct ("a",1), struct ("a",1),struct ("a",1,"b",2)), false) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
400 %!assert (isequal (struct ("a",1), struct ("b",1)), false) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
401 %!assert (isequal (struct ("a",1), struct ("a",1), struct ("b",1)), false) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
402 %!assert (isequal (struct ("a",1,"b",2), struct ("a",1,"b",2)), true) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
403 %!assert (isequal (struct ("a",1,"b",2), struct ("a",1,"b",2), |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
404 %! struct ("a",1,"b",2)), true) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
405 %!assert (isequal (struct ("a",1,"b",2), struct ("b",2,"a",1)), true) |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
406 %!assert (isequal (struct ("a",1,"b",2), struct ("a",1,"b",2), |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
407 %! struct ("b",2,"a",1)), true) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
408 %!assert (isequal (struct ("a","abc","b",2), struct ("a","abc","b",2)), true) |
24634
ab2321d4ba03
maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
409 %!assert (isequal (struct ("a","abc","b",2), struct ("a","abc","b",2), |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
410 %! struct ("a","abc","b",2)), true) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
411 |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
412 ## recursive structure |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18786
diff
changeset
|
413 %!test |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
414 %! x.a = "a1"; |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
415 %! x.b.a = "ba1"; |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
416 %! x.b.b = "bb1"; |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
417 %! assert (isequal (x, x), true); |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
418 %! assert (isequal (x, x, x), true); |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
419 %! y = x; |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
420 %! y.b.b = "bb2"; |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
421 %! assert (isequal (x, y), false); |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
422 %! assert (isequal (x, x, y), false); |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
423 %! y = x; |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
424 %! y.b = rmfield (y.b, "b"); |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
425 %! y.b.b.a = "bba1"; |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
426 %! assert (isequal (x, y), false); |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
427 %! assert (isequal (x, x, y), false); |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
428 |
24326
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
429 ## struct array |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
430 %!test |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
431 %! x(1).a = 'A'; |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
432 %! x(2).a = magic (3); |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
433 %! assert (isequal (x, x), true); |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
434 %! assert (isequal (x, x, x), true); |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
435 %! y = x; |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
436 %! y(2).a = { magic(3) }; |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
437 %! assert (isequal (x, y), false); |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
438 %! assert (isequal (x, x, y), false); |
a35bceb4b519
isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents:
24313
diff
changeset
|
439 |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
440 ## test cellstr |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
441 %!assert (isequal (cell (1,1), cell (1,1)), true) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
442 %!assert (isequal (cell (1,1), cell (1,2)), false) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
443 %!assert (isequal ({"a","b";"c","d"}, {"a","b";"c","d"}), true) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
444 %!assert (isequal ({"a","b";"c","d"}, {"a","b";"c","d"}, {"a","b";"c","d"}), |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
445 %! true) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
446 %!assert (isequal ({"a","b","c","d"}, {"a";"b";"c";"d"}), false) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
447 %!assert (isequal ({"a","b","c","d"}, {"a","b","c","d"}, {"a";"b";"c";"d"}), |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
448 %! false) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
449 %!assert (isequal (["a","b","c","d"], {"a","b","c","d"}), false) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
450 %!assert (isequal (["a","b","c","d"], ["a","b","c","d"], {"a","b","c","d"}), |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
451 %! false) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
452 %!test |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
453 %! x = { ["ab"; "cd"] ; ["ef"; "gh"] }; |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
454 %! assert (isequal (x, x), true); |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
455 %! assert (isequal (x, x, x), true); |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
456 %! y = x; |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
457 %! y(2) = ["ef"; "gH"]; |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
458 %! assert (isequal (x, y), false); |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
459 %! assert (isequal (x, x, y), false); |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
460 |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
461 ## test cells |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
462 %!assert (isequal (cell (1,1), cell (1,1)), true) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
463 %!assert (isequal (cell (1,1), cell (1,1), cell (1,1)), true) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
464 %!assert (isequal (cell (1,1), cell (1,2)), false) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
465 %!assert (isequal (cell (1,1), cell (1,1), cell (1,2)), false) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
466 %!assert (isequal ({"a",1}, {"a",1}), true) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
467 %!assert (isequal ({"a",1}, {"a",1}, {"a",1}), true) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
468 %!assert (isequal ({"a",1}, {"a",2}), false) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
469 %!assert (isequal ({"a",1}, {"a",1}, {"a",2}), false) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
470 %!assert (isequal ({"a",1}, {"b",1}), false) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
471 %!assert (isequal ({"a",1}, {"a",1}, {"b",1}), false) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
472 %!assert (isequal ({"a",1,"b",2}, {"a",1,"b",2}), true) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
473 %!assert (isequal ({"a",1,"b",2}, {"a",1,"b",2}, {"a",1,"b",2}), true) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
474 %!assert (isequal ({"a",1,"b",2}, {"b",2,"a",1}), false) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
475 %!assert (isequal ({"a",1,"b",2}, {"a",1,"b",2}, {"b",2,"a",1}), false) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
476 %!assert (isequal ({"a","abc","b",2}, {"a","abc","b",2}), true) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
477 %!assert (isequal ({"a","abc","b",2}, {"a","abc","b",2}, {"a","abc","b",2}), |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
478 %! true) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
479 |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
480 ## recursive cell |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
481 %!test |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
482 %! x = cell (1,3); |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
483 %! x{1} = {[1], [1 2]}; |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
484 %! x{2} = true; |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
485 %! x{3} = {{"hello"}, {"world"}}; |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
486 %! assert (isequal (x, x)); |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
487 %! y = x; |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
488 %! y{3}{1}{1} = "goodbye"; |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
489 %! assert (isequal (x, y), false); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
490 |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
491 ## test function_handle |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
492 %!test |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
493 %! fcn = @(x) x.^2; |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
494 %! assert (isequal (fcn, fcn), true); |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
495 %! assert (isequal (fcn, fcn, fcn), true); |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
496 %! assert (isequal (fcn, @(x) x.^2), false); |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
497 %! assert (isequal (fcn, fcn, @(x) x.^2), false); |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
498 %! assert (isequal (@(x) x.^2, fcn), false); |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
499 %! assert (isequal (@(x) x.^2, @(x) x.^2, fcn), false); |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
500 |
17278
79d4b6089968
Fix isequal for sparse matrix (bug #37321)
Stefan Mahr <dac922@gmx.de>
parents:
16935
diff
changeset
|
501 ## test for sparse matrices |
24970
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
502 %!shared A, Z |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
503 %! A = sprand (2^31, 1000, 2^(-31)); |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
504 %! Z = sparse (2^31, 1000); |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
505 %!assert (isequal (sparse ([]), []), true) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
506 %!assert (isequal (sparse ([]), sparse ([]), []), true) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
507 %!assert (isequal ([], sparse ([])), true) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
508 %!assert (isequal ([], [], sparse ([])), true) |
17278
79d4b6089968
Fix isequal for sparse matrix (bug #37321)
Stefan Mahr <dac922@gmx.de>
parents:
16935
diff
changeset
|
509 %!assert (isequal (sparse (0,1), sparse (0,1)), true) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
510 %!assert (isequal (sparse (0,1), sparse (0,1), sparse (0,1)), true) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
511 %!assert (isequal (sparse (0,1), zeros (0,1)), true) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
512 %!assert (isequal (sparse (0,1), sparse (0,1), zeros (0,1)), true) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
513 %!assert (isequal (sparse (2,2), sparse (2,2)), true) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
514 %!assert (isequal (sparse (2,2), sparse (2,2), sparse (2,2)), true) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
515 %!assert (isequal (zeros (2,2), sparse (2,2)), true) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
516 %!assert (isequal (zeros (2,2), zeros (2,2), sparse (2,2)), true) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
517 %!assert (isequal (speye (1), eye (1)), true) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
518 %!assert (isequal (speye (1), speye (1), eye (1)), true) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
519 %!assert (isequal (eye (300), speye (300)), true) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
520 %!assert (isequal (eye (300), eye (300), speye (300)), true) |
17278
79d4b6089968
Fix isequal for sparse matrix (bug #37321)
Stefan Mahr <dac922@gmx.de>
parents:
16935
diff
changeset
|
521 %!assert (isequal (sparse (0,1), sparse (1,0)), false) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
522 %!assert (isequal (sparse (0,1), sparse (0,1), sparse (1,0)), false) |
24970
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
523 %!assert (isequal (Z, Z), true) |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
524 %!assert (isequal (A, A), true) |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
525 %!assert (isequal (A, Z), false) |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
526 %!assert (isequal (Z, Z, Z), true) |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
527 %!assert (isequal (A, A, A), true) |
0e5ae3ecda1a
Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24634
diff
changeset
|
528 %!assert (isequal (A, Z, A), false) |
17278
79d4b6089968
Fix isequal for sparse matrix (bug #37321)
Stefan Mahr <dac922@gmx.de>
parents:
16935
diff
changeset
|
529 |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
530 ## test NaN |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
531 %!assert (isequal (NaN, NaN), false) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
532 %!assert (isequal (NaN, NaN, NaN), false) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
533 %!assert (isequal (NaN, Inf), false) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
534 %!assert (isequal (NaN, Inf, Inf), false) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
535 %!assert (isequal (NaN, 1.0), false) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
536 %!assert (isequal (NaN, 1.0, 1.0), false) |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
537 %!assert (isequal ([1,2,NaN,4], [1,2,NaN,4]), false) |
24308
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
538 %!assert (isequal ([1,2,NaN,4], [1,2,NaN,4], [1,2,NaN,4]), false) |
606f3866cdb7
__isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
539 %!assert (isequal (struct ("a",NaN,"b",2), struct ("a",NaN,"b",2)), false) |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18786
diff
changeset
|
540 %!assert (isequal (struct ("a",NaN,"b",2), struct ("a",NaN,"b",2), |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
541 %! struct ("a",NaN,"b",2)), false) |
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
542 |
24312
9d25e88d83f6
isequal.m, isequaln.m: Return a full, non-sparse, logical value for compatibility.
Rik <rik@octave.org>
parents:
24309
diff
changeset
|
543 ## Matlab compatibility |
9d25e88d83f6
isequal.m, isequaln.m: Return a full, non-sparse, logical value for compatibility.
Rik <rik@octave.org>
parents:
24309
diff
changeset
|
544 %!assert (isequal (sparse (1), sparse (1)), true) |
24313
7ba994876f3a
isequal.m: Fix typo in BIST test (bug #51403).
Rik <rik@octave.org>
parents:
24312
diff
changeset
|
545 %!assert (isequal (sparse (1), sparse (1)), sparse (1), true) |
24312
9d25e88d83f6
isequal.m, isequaln.m: Return a full, non-sparse, logical value for compatibility.
Rik <rik@octave.org>
parents:
24309
diff
changeset
|
546 |
18786
ff613b6a7b6f
Add tests for empty value and correct alphanumerical value comparision of isequal (bug #42408).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
17744
diff
changeset
|
547 ## test input validation |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
548 %!error <Invalid call> isequal () |
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
549 %!error <Invalid call> isequal (1) |