annotate scripts/general/private/__isequal__.m @ 18819:1f170b211be3

Make isequal matlab compatible when comparing char to numeric (bug #42408). Increase performance of isequal. __isequal__.m: When there are mixed operands (char, numeric) use '==' rather than strcmp for equality. Use cellindexmat instead of for loop when testing cells. Use cellfun call with ndims to check rough size equality of objects.
author Rik <rik@octave.org>
date Tue, 27 May 2014 14:15:08 -0700
parents fcd87f68af4f
children db92e7e28e1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17338
diff changeset
1 ## Copyright (C) 2000-2013 Paul Kienzle
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
2 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6945
diff changeset
3 ## This file is part of Octave.
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
4 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6945
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6945
diff changeset
6 ## under the terms of the GNU General Public License as published by
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6945
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6945
diff changeset
8 ## your option) any later version.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6945
diff changeset
9 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6945
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6945
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6945
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6945
diff changeset
13 ## General Public License for more details.
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
14 ##
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
15 ## 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: 6945
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6945
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
18
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6609
diff changeset
19 ## Undocumented internal function.
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6609
diff changeset
20
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
21 ## -*- texinfo -*-
5550
815926a781f6 [project @ 2005-11-30 03:22:53 by jwe]
jwe
parents: 5549
diff changeset
22 ## @deftypefn {Function File} {} __isequal__ (@var{nans_compare_equal}, @var{x1}, @var{x2}, @dots{})
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
23 ## Undocumented internal function.
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
24 ## @end deftypefn
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
25
5550
815926a781f6 [project @ 2005-11-30 03:22:53 by jwe]
jwe
parents: 5549
diff changeset
26 ## Return true if @var{x1}, @var{x2}, @dots{} are all equal and
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
27 ## @var{nans_compare_equal} evaluates to false.
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
28 ##
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
29 ## If @var{nans_compare_equal} evaluates to true, then assume NaN == NaN.
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
30
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
31 ## Modified by: William Poetra Yoga Hadisoeseno
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
32
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
33 ## Algorithm:
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
34 ##
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
35 ## 1. Determine the class of x
18819
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
36 ## 2. If x and all other arguments have the same class, then check that the
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
37 ## number of dimensions and then the size of each dimension match.
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
38 ## If not all arguments share the same class, then verify that all of the
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
39 ## arguments belong to a comparable "numeric" class which includes
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
40 ## numeric, logical, and character arrays. Check that number of dimensions
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
41 ## and size of each dimension match.
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
42 ## 3. For each argument after x, compare it for equality with x:
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
43 ## a. struct compare each member by name, not by order (recursive)
18819
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
44 ## b. object converted to struct, and then compared as stated above
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
45 ## c. cell compare each member by order (recursive)
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
46 ## d. char compare each member with strcmp
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
47 ## e fcn_handle compare using overloade 'eq' operator
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
48 ## f. <other> compare each nonzero member, and assume NaN == NaN
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
49 ## if nans_compare_equal is nonzero.
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
50
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
51 function t = __isequal__ (nans_compare_equal, x, varargin)
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
52
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
53 l_v = nargin - 2;
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
54
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
55 ## Generic tests.
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
56
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 6157
diff changeset
57 ## All arguments must either be of the same class or they must be
18819
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
58 ## "numeric" values.
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
59 t = (all (strcmp (class (x),
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
60 cellfun ("class", varargin, "uniformoutput", false)))
18819
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
61 || ((isreal (x) || isnumeric (x))
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
62 && all (cellfun ("isreal", varargin)
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
63 | cellfun ("isnumeric", varargin))));
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 6157
diff changeset
64
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
65 if (t)
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
66 ## Test that everything has the same number of dimensions.
18819
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
67 t = all (ndims (x) == cellfun ("ndims", varargin));
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
68 endif
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
69
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
70 if (t)
18819
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
71 ## Test that everything is the same size since the dimensionality matches.
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
72 nd = ndims (x);
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
73 k = 1;
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
74 do
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
75 t = all (size (x,k) == cellfun ("size", varargin, k));
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
76 until (!t || k++ == nd);
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
77 endif
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
78
11459
990c9cb52e5f __isequal__: compare objects as if they are structures
John W. Eaton <jwe@octave.org>
parents: 11191
diff changeset
79 ## From here on, compare objects as if they were structures.
18819
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
80 if (t && isobject (x))
11475
caf1fd72f587 __isequal__: avoid possible overloading of struct function for objects
John W. Eaton <jwe@octave.org>
parents: 11459
diff changeset
81 x = builtin ("struct", x);
18447
ff7e7928f160 Fix isequal* parse failure when comparing object to non-object (bug #41531).
Felipe G. Nievinski <fgnievinski@gmail.com>
parents: 17744
diff changeset
82 for i = 1:numel (varargin)
ff7e7928f160 Fix isequal* parse failure when comparing object to non-object (bug #41531).
Felipe G. Nievinski <fgnievinski@gmail.com>
parents: 17744
diff changeset
83 varargin{i} = builtin ("struct", varargin{i});
ff7e7928f160 Fix isequal* parse failure when comparing object to non-object (bug #41531).
Felipe G. Nievinski <fgnievinski@gmail.com>
parents: 17744
diff changeset
84 endfor
11459
990c9cb52e5f __isequal__: compare objects as if they are structures
John W. Eaton <jwe@octave.org>
parents: 11191
diff changeset
85 endif
990c9cb52e5f __isequal__: compare objects as if they are structures
John W. Eaton <jwe@octave.org>
parents: 11191
diff changeset
86
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
87 if (t)
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
88 ## Check individual classes.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
89 if (isstruct (x))
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
90 ## Test the number of fields.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
91 fn_x = fieldnames (x);
18538
fcd87f68af4f Deprecate nfields and replace with numfields.
Rik <rik@octave.org>
parents: 18447
diff changeset
92 l_fn_x = numfields (x);
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
93 fn_v = cellfun ("fieldnames", varargin, "uniformoutput", false);
18819
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
94 t = all (l_fn_x == cellfun ("numel", fn_v));
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
95
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
96 ## Test that all the names are equal.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
97 idx = 0;
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
98 s_fn_x = sort (fn_x);
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
99 while (t && idx < l_v)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
100 idx++;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
101 ## We'll allow the fieldnames to be in a different order.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
102 t = all (strcmp (s_fn_x, sort (fn_v{idx})));
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
103 endwhile
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
104
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
105 idx = 0;
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
106 while (t && idx < l_fn_x)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
107 ## Test that all field values are equal.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
108 idx++;
18819
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
109 args = cell (1, 2+l_v);
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
110 args(1:2) = {nans_compare_equal, {x.(fn_x{idx})}};
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
111 for argn = 1:l_v
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
112 args{argn+2} = {varargin{argn}.(fn_x{idx})};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
113 endfor
18819
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
114 ## Minimize function calls by calling for all the arguments at once.
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
115 t = __isequal__ (args{:});
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
116 endwhile
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
117
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
118 elseif (iscell (x))
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
119 ## Check that each element of a cell is equal.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
120 l_x = numel (x);
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
121 idx = 0;
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
122 while (t && idx < l_x)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
123 idx++;
18819
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
124 args = cell (1, 2+l_v);
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
125 args(1:2) = {nans_compare_equal, x{idx}};
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
126 args(3:end) = [cellindexmat(varargin, idx){:}];
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
127
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
128 t = __isequal__ (args{:});
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
129 endwhile
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
130
18819
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
131 elseif (ischar (x) && all (cellfun ("isclass", varargin, "char")))
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
132 ## Sizes are equal already, so we can just make everything into a
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
133 ## row and test the rows.
18819
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
134 n_x = numel (x);
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
135 strings = cell (1, l_v);
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
136 for i = 1:l_v
18819
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
137 strings{i} = reshape (varargin{i}, 1, n_x);
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
138 endfor
18819
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
139 t = all (strcmp (reshape (x, 1, n_x), strings));
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
140
10260
14d5fee02b3b basic support for comparing function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9899
diff changeset
141 elseif (isa (x, "function_handle"))
14d5fee02b3b basic support for comparing function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9899
diff changeset
142 ## The == operator is overloaded for handles.
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
143 t = all (cellfun ("eq", {x}, varargin));
10260
14d5fee02b3b basic support for comparing function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9899
diff changeset
144
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
145 else
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
146 ## Check the numeric types.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
147
10650
f0dc41c824ce Replace calls to deprecated functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
148 f_x = find (x);
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
149 l_f_x = length (f_x);
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
150 x = x(f_x);
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
151 for argn = 1:l_v
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
152 y = varargin{argn};
10650
f0dc41c824ce Replace calls to deprecated functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
153 f_y = find (y);
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
154
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
155 t = (l_f_x == length (f_y)) && all (f_x == f_y);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
156 if (!t)
17278
79d4b6089968 Fix isequal for sparse matrix (bug #37321)
Stefan Mahr <dac922@gmx.de>
parents: 17176
diff changeset
157 break;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
158 endif
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
159
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
160 y = y(f_y);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
161 m = (x == y);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
162 t = all (m);
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
163
11126
304b0ed4ca56 __isequal__.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 11125
diff changeset
164 if (!t && nans_compare_equal)
304b0ed4ca56 __isequal__.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 11125
diff changeset
165 t = isnan (x(!m)) && isnan (y(!m));
11125
8a8eb099502e Fix bug #31239 in isequalwithequalnans.m
Rik <octave@nomad.inbox5.com>
parents: 10650
diff changeset
166 endif
8a8eb099502e Fix bug #31239 in isequalwithequalnans.m
Rik <octave@nomad.inbox5.com>
parents: 10650
diff changeset
167
8a8eb099502e Fix bug #31239 in isequalwithequalnans.m
Rik <octave@nomad.inbox5.com>
parents: 10650
diff changeset
168 if (!t)
17278
79d4b6089968 Fix isequal for sparse matrix (bug #37321)
Stefan Mahr <dac922@gmx.de>
parents: 17176
diff changeset
169 break;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
170 endif
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
171 endfor
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
172
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
173 endif
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
174 endif
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
175
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
176 endfunction
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 17285
diff changeset
177