annotate scripts/general/isequal.m @ 31202:434b5a1b9498

isequal.m: Add ability to compare Java objects (bug #62930) * isequal.m: Add elseif clause to detect Java objects and use built-in Java "equals" method for comparison. Add BIST test for Java object comparison.
author Rik <rik@octave.org>
date Thu, 25 Aug 2022 15:35:25 -0700
parents 83f9f8bda883
children 4c2b83516eb7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 2000-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 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
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
7 ##
5181
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
8 ## This file is part of Octave.
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
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
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
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
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
14 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
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
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
19 ##
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
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
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
25
5182
5b361aa47dff [project @ 2005-03-03 06:21:47 by jwe]
jwe
parents: 5181
diff changeset
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
815926a781f6 [project @ 2005-11-30 03:22:53 by jwe]
jwe
parents: 5549
diff changeset
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
5b361aa47dff [project @ 2005-03-03 06:21:47 by jwe]
jwe
parents: 5181
diff changeset
30 ## @end deftypefn
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
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
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
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
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5720
diff changeset
52 print_usage ();
5550
815926a781f6 [project @ 2005-11-30 03:22:53 by jwe]
jwe
parents: 5549
diff changeset
53 endif
5181
41cd70503c72 [project @ 2005-03-03 05:49:55 by jwe]
jwe
parents: 5178
diff changeset
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
31202
434b5a1b9498 isequal.m: Add ability to compare Java objects (bug #62930)
Rik <rik@octave.org>
parents: 30565
diff changeset
174 elseif (isjava (x))
434b5a1b9498 isequal.m: Add ability to compare Java objects (bug #62930)
Rik <rik@octave.org>
parents: 30565
diff changeset
175 try
434b5a1b9498 isequal.m: Add ability to compare Java objects (bug #62930)
Rik <rik@octave.org>
parents: 30565
diff changeset
176 tf = x.equals (y);
434b5a1b9498 isequal.m: Add ability to compare Java objects (bug #62930)
Rik <rik@octave.org>
parents: 30565
diff changeset
177 catch
434b5a1b9498 isequal.m: Add ability to compare Java objects (bug #62930)
Rik <rik@octave.org>
parents: 30565
diff changeset
178 error ('isequal: Java object does not implement "equals" function');
434b5a1b9498 isequal.m: Add ability to compare Java objects (bug #62930)
Rik <rik@octave.org>
parents: 30565
diff changeset
179 end_try_catch
434b5a1b9498 isequal.m: Add ability to compare Java objects (bug #62930)
Rik <rik@octave.org>
parents: 30565
diff changeset
180
24309
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
181 else
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
182 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
183
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
184 endif
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
185
28943
e3a337a57588 maint: Use only one '#' character for comments that trail code.
Rik <rik@octave.org>
parents: 28896
diff changeset
186 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
187
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
188 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
189 ## 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
190 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
191 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
192 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
193 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
194 endwhile
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
195
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
196 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
197
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
198 if (issparse (x))
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
199 ## sparse types.
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
200
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
201 idx = 1;
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
202 [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
203 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
204 y = varargin{idx};
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
205 [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
206 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
207 && 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
208
24970
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
209 idx += 1;
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
210 endwhile
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
211
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
212 else
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
213 ## 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
214
24970
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
215 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
216 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
217 y = varargin{idx};
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
218 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
219 tf = all (m(:));
24970
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
220
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
221 idx += 1;
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
222 endwhile
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
223
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
224 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
225
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
226 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
227 ## 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
228
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
229 ## 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
230 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
231 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
232 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
233 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
234
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
235 ## 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
236 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
237 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
238 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
239 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
240 ## 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
241 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
242 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
243 endwhile
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
244 endif
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
245
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
246 ## 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
247 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
248 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
249 if (isscalar (x))
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
250 for fldnm = fnm_x.'
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
251 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
252 for argn = 1:nvarargin
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
253 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
254 endfor
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
255
30558
83aeaba707d8 doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents: 29359
diff changeset
256 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
257
30558
83aeaba707d8 doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents: 29359
diff changeset
258 if (! tf)
24326
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
259 break;
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
260 endif
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
261 endfor
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
262 else
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
263 ## 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
264 ## 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
265 for fldnm = fnm_x.'
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
266 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
267 for argn = 1:nvarargin
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
268 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
269 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
270
30558
83aeaba707d8 doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents: 29359
diff changeset
271 tf = isequal (args{:});
24326
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
272
30558
83aeaba707d8 doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents: 29359
diff changeset
273 if (! tf)
24326
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
274 break;
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
275 endif
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
276 endfor
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
277 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
278 endif
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
279
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
280 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
281 ## 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
282 ## 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
283 ## 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
284 ## 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
285 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
286 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
287 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
288 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
289 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
290 endwhile
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
291
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
292 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
293 ## 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
294 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
295 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
296 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
297 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
298 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
299 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
300
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 = 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
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 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
304 endwhile
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
305
25803
23483673ba43 Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents: 25054
diff changeset
306 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
307 ## 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
308 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
309
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
310 else
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
311 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
312
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
313 endif
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
314
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
315 endif
1262d7c4712e Promote __iseqal__.m to isequal.m, isequaln.m for 20% performance benefit (bug #51403).
Rik <rik@octave.org>
parents: 24308
diff changeset
316 endif
12604
132c89bb44e3 maint: Refactor general/isXXX.m scripts to put input validation first.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
317
30558
83aeaba707d8 doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents: 29359
diff changeset
318 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
319
5178
6758c11b5b99 [project @ 2005-03-03 05:18:04 by jwe]
jwe
parents:
diff changeset
320 endfunction
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents: 5393
diff changeset
321
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
322
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
323 ## 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
324 %!assert (isequal ([], []), true)
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
325 %!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
326 %!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
327 %!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
328 %!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
329
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
330 ## 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
331 %!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
332 %!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
333 %!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
334 %!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
335 %!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
336 %!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
337 %!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
338 %!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
339 %!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
340 %!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
341
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
342 ## General tests
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
343 %!test
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
344 %! A = 1:8;
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
345 %! B = reshape (A, 2, 2, 2);
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
346 %! assert (isequal (A, B), false);
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
347 %! assert (isequal (A, A, B), false);
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
348 %!test
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
349 %! A = reshape (1:8, 2, 2, 2);
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
350 %! B = A;
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
351 %! assert (isequal (A, B), true);
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
352 %! assert (isequal (A, A, B), true);
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
353 %!test
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
354 %! A = reshape (1:8, 2, 4);
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
355 %! B = reshape (A, 2, 2, 2);
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
356 %! assert (isequal (A, B), false);
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
357 %! assert (isequal (A, A, B), false);
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
358
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
359 ## test characters and strings
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
360 %!assert (isequal ('a', "a"), true)
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
361 %!assert (isequal ('a', 'a', "a"), true)
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
362 %!assert (isequal ("abab", ["a", "b", "a", "b"]), true)
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
363 %!assert (isequal ("abab", "abab", ["a", "b", "a", "b"]), true)
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"]), true)
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
365 %!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
366 %! true)
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
367 %!assert (isequal (["test ";"strings"], ["test ";"strings"]), true)
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
368 %!assert (isequal (["test ";"strings"], ["test ";"strings"],
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
369 %! ["test ";"strings"]), true)
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
370 %!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
371 %!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
372 %! false)
9899
9f25290a35e8 more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
373
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
374 ## test all numeric built-in primitives
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
375 %!assert (isequal (false, 0))
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
376 %!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
377 %!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
378 %! 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
379 %! 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
380 %! double (0), single (0),
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
381 %! double (complex (0,0)), single (complex (0,0)),
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
382 %! sparse (false), sparse (logical (0)),
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
383 %! sparse (double (0)), sparse (single (0)),
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
384 %! sparse (double (complex (0,0))),
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
385 %! 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
386 %! true)
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18786
diff changeset
387 %!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
388 %! 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
389 %! 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
390 %! double (1), single (1),
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
391 %! double (complex (1,0)), single (complex (1,0)),
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
392 %! sparse (true), sparse (logical (1)),
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
393 %! sparse (double (1)), sparse (single (1)),
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
394 %! sparse (double (complex (1,0))),
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
395 %! 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
396 %! 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
397
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
398 ## test structures
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
399 %!assert (isequal (struct ([]), struct ([])), true)
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
400 %!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
401 %!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
402 %!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
403 %!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
404 %!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
405 %!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
406 %!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
407 %!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
408 %!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
409 %!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
410 %!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
411 %! 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
412 %!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
413 %!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
414 %! 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
415 %!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
416 %!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
417 %! 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
418
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 ## recursive structure
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18786
diff changeset
420 %!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
421 %! 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
422 %! 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
423 %! x.b.b = "bb1";
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
424 %! 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
425 %! 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
426 %! 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
427 %! 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
428 %! assert (isequal (x, y), false);
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
429 %! 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
430 %! 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
431 %! 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
432 %! 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
433 %! assert (isequal (x, y), false);
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
434 %! assert (isequal (x, x, y), false);
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
435
24326
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
436 ## struct array
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
437 %!test
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
438 %! x(1).a = 'A';
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
439 %! 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
440 %! 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
441 %! 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
442 %! y = x;
a35bceb4b519 isequal.m, isequaln.m: Fix comparsion of struct arrays (bug #51403).
Rik <rik@octave.org>
parents: 24313
diff changeset
443 %! 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
444 %! 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
445 %! 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
446
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
447 ## test cellstr
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
448 %!assert (isequal (cell (1,1), cell (1,1)), true)
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
449 %!assert (isequal (cell (1,1), cell (1,2)), 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"}), true)
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
451 %!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
452 %! true)
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
453 %!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
454 %!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
455 %! false)
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
456 %!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
457 %!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
458 %! false)
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
459 %!test
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
460 %! x = { ["ab"; "cd"] ; ["ef"; "gh"] };
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
461 %! assert (isequal (x, x), true);
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
462 %! assert (isequal (x, x, x), true);
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
463 %! y = x;
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
464 %! y(2) = ["ef"; "gH"];
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
465 %! assert (isequal (x, y), false);
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
466 %! 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
467
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 ## 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
469 %!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
470 %!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
471 %!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
472 %!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
473 %!assert (isequal ({"a",1}, {"a",1}), true)
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
474 %!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
475 %!assert (isequal ({"a",1}, {"a",2}), false)
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
476 %!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
477 %!assert (isequal ({"a",1}, {"b",1}), false)
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
478 %!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
479 %!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
480 %!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
481 %!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
482 %!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
483 %!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
484 %!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
485 %! 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
486
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 ## 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
488 %!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
489 %! 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
490 %! 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
491 %! 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
492 %! 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
493 %! 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
494 %! 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
495 %! 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
496 %! 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
497
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
498 ## test function_handle
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
499 %!test
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
500 %! fcn = @(x) x.^2;
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
501 %! assert (isequal (fcn, fcn), true);
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
502 %! assert (isequal (fcn, fcn, fcn), true);
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
503 %! assert (isequal (fcn, @(x) x.^2), false);
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
504 %! assert (isequal (fcn, fcn, @(x) x.^2), false);
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
505 %! assert (isequal (@(x) x.^2, fcn), false);
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
506 %! 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
507
17278
79d4b6089968 Fix isequal for sparse matrix (bug #37321)
Stefan Mahr <dac922@gmx.de>
parents: 16935
diff changeset
508 ## 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
509 %!shared A, Z
0e5ae3ecda1a Make isequal handle large sparse matrices (bug #45171).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24634
diff changeset
510 %! 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
511 %! 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
512 %!assert (isequal (sparse ([]), []), true)
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
513 %!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
514 %!assert (isequal ([], sparse ([])), true)
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
515 %!assert (isequal ([], [], sparse ([])), true)
17278
79d4b6089968 Fix isequal for sparse matrix (bug #37321)
Stefan Mahr <dac922@gmx.de>
parents: 16935
diff changeset
516 %!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
517 %!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
518 %!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
519 %!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
520 %!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
521 %!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
522 %!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
523 %!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
524 %!assert (isequal (speye (1), eye (1)), true)
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
525 %!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
526 %!assert (isequal (eye (300), speye (300)), true)
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
527 %!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
528 %!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
529 %!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
530 %!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
531 %!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
532 %!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
533 %!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
534 %!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
535 %!assert (isequal (A, Z, A), false)
17278
79d4b6089968 Fix isequal for sparse matrix (bug #37321)
Stefan Mahr <dac922@gmx.de>
parents: 16935
diff changeset
536
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 ## 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
538 %!assert (isequal (NaN, NaN), false)
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
539 %!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
540 %!assert (isequal (NaN, Inf), false)
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
541 %!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
542 %!assert (isequal (NaN, 1.0), false)
24308
606f3866cdb7 __isequal__.m: Rewrite function for performance.
Rik <rik@octave.org>
parents: 23220
diff changeset
543 %!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
544 %!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
545 %!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
546 %!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
547 %!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
548 %! 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
549
24312
9d25e88d83f6 isequal.m, isequaln.m: Return a full, non-sparse, logical value for compatibility.
Rik <rik@octave.org>
parents: 24309
diff changeset
550 ## Matlab compatibility
9d25e88d83f6 isequal.m, isequaln.m: Return a full, non-sparse, logical value for compatibility.
Rik <rik@octave.org>
parents: 24309
diff changeset
551 %!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
552 %!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
553
31202
434b5a1b9498 isequal.m: Add ability to compare Java objects (bug #62930)
Rik <rik@octave.org>
parents: 30565
diff changeset
554 ## Java objects
434b5a1b9498 isequal.m: Add ability to compare Java objects (bug #62930)
Rik <rik@octave.org>
parents: 30565
diff changeset
555 %!test <*62930>
434b5a1b9498 isequal.m: Add ability to compare Java objects (bug #62930)
Rik <rik@octave.org>
parents: 30565
diff changeset
556 %! int1 = javaObject ("java.lang.Integer", 1.0);
434b5a1b9498 isequal.m: Add ability to compare Java objects (bug #62930)
Rik <rik@octave.org>
parents: 30565
diff changeset
557 %! int2 = javaObject ("java.lang.Integer", 2.0);
434b5a1b9498 isequal.m: Add ability to compare Java objects (bug #62930)
Rik <rik@octave.org>
parents: 30565
diff changeset
558 %! assert (isequal (int1, int1));
434b5a1b9498 isequal.m: Add ability to compare Java objects (bug #62930)
Rik <rik@octave.org>
parents: 30565
diff changeset
559 %! assert (! isequal (int1, 1.0));
434b5a1b9498 isequal.m: Add ability to compare Java objects (bug #62930)
Rik <rik@octave.org>
parents: 30565
diff changeset
560 %! assert (! isequal (int1, int2));
434b5a1b9498 isequal.m: Add ability to compare Java objects (bug #62930)
Rik <rik@octave.org>
parents: 30565
diff changeset
561
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
562 ## 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
563 %!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
564 %!error <Invalid call> isequal (1)