annotate scripts/general/private/__isequal__.m @ 21562:6c2fd62db1f7

maint: Eliminate accidental double spaces in code. * make_int.cc, file-editor-tab.h, file-editor.cc, shortcut-manager.h, __contourc__.cc, cellfun.cc, debug.cc, errwarn.h, graphics.in.h, jit-ir.h, oct-stream.cc, quadcc.cc, qz.cc, sparse-xdiv.cc, symtab.cc, __init_fltk__.cc, ov-class.cc, ov-float.h, ov-scalar.h, op-int.h, CNDArray.cc, CSparse.cc, MSparse.cc, Sparse.cc, boolNDArray.cc, chNDArray.cc, dNDArray.cc, dSparse.cc, fCNDArray.cc, fNDArray.cc, int16NDArray.cc, int32NDArray.cc, int64NDArray.cc, int8NDArray.cc, intNDArray.cc, uint16NDArray.cc, uint32NDArray.cc, uint64NDArray.cc, uint8NDArray.cc, randgamma.h, randmtzig.h, randpoisson.c, randpoisson.h, Sparse-op-defs.h, oct-time.cc, kpse.cc, lo-array-errwarn.h, lo-ieee.h, del2.m, num2str.m, __isequal__.m, lookfor.m, hsv2rgb.m, colorspace_conversion_revert.m, fminbnd.m, create_pkgadddel.m, shading.m, struct2hdl.m, gallery.m, discrete_cdf.m, kolmogorov_smirnov_test.m, assert.m, datestr.m, classes.tst, jit.tst: Eliminate accidental double spaces in code.
author Rik <rik@octave.org>
date Wed, 30 Mar 2016 15:19:12 -0700
parents 77f5591878bf
children bac0d6f07a3e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19597
diff changeset
1 ## Copyright (C) 2000-2015 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 -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20735
diff changeset
22 ## @deftypefn {} {} __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
18785
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)
20072
8e42898f4d73 Don't throw classdef-to-struct warning during isequal (bug #43759).
Rik <rik@octave.org>
parents: 19697
diff changeset
44 ## b. object convert to struct, and then compare as stated above
18785
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
21562
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 20955
diff changeset
47 ## e fcn_handle compare using overloaded 'eq' operator
18785
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
18785
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)))
18785
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.
20890
ef9b2a88fbb5 Fixed isequal for comparison of objects with overridden size (bug #44334)
Oliver Heimlich <oheim@posteo.de>
parents: 20072
diff changeset
67 t = all (builtin ("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)
18785
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
20890
ef9b2a88fbb5 Fixed isequal for comparison of objects with overridden size (bug #44334)
Oliver Heimlich <oheim@posteo.de>
parents: 20072
diff changeset
75 t = all (builtin ("size", x, k) == cellfun ("size", varargin, k));
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20907
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.
18785
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))
20072
8e42898f4d73 Don't throw classdef-to-struct warning during isequal (bug #43759).
Rik <rik@octave.org>
parents: 19697
diff changeset
81 ## Locally suppress class-to-struct warning. We know what we are doing.
8e42898f4d73 Don't throw classdef-to-struct warning during isequal (bug #43759).
Rik <rik@octave.org>
parents: 19697
diff changeset
82 warning ("off", "Octave:classdef-to-struct", "local");
11475
caf1fd72f587 __isequal__: avoid possible overloading of struct function for objects
John W. Eaton <jwe@octave.org>
parents: 11459
diff changeset
83 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
84 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
85 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
86 endfor
11459
990c9cb52e5f __isequal__: compare objects as if they are structures
John W. Eaton <jwe@octave.org>
parents: 11191
diff changeset
87 endif
990c9cb52e5f __isequal__: compare objects as if they are structures
John W. Eaton <jwe@octave.org>
parents: 11191
diff changeset
88
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
89 if (t)
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
90 ## Check individual classes.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
91 if (isstruct (x))
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
92 ## Test the number of fields.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
93 fn_x = fieldnames (x);
18538
fcd87f68af4f Deprecate nfields and replace with numfields.
Rik <rik@octave.org>
parents: 18447
diff changeset
94 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
95 fn_v = cellfun ("fieldnames", varargin, "uniformoutput", false);
18785
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
96 t = all (l_fn_x == cellfun ("numel", fn_v));
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
97
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
98 ## Test that all the names are equal.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
99 idx = 0;
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
100 s_fn_x = sort (fn_x);
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
101 while (t && idx < l_v)
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20072
diff changeset
102 idx += 1;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
103 ## We'll allow the fieldnames to be in a different order.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
104 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
105 endwhile
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
106
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
107 idx = 0;
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
108 while (t && idx < l_fn_x)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
109 ## Test that all field values are equal.
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20072
diff changeset
110 idx += 1;
18785
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
111 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
112 args(1:2) = {nans_compare_equal, {x.(fn_x{idx})}};
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
113 for argn = 1:l_v
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
114 args{argn+2} = {varargin{argn}.(fn_x{idx})};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
115 endfor
18785
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
116 ## 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
117 t = __isequal__ (args{:});
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
118 endwhile
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
119
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
120 elseif (iscell (x))
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
121 ## Check that each element of a cell is equal.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
122 l_x = numel (x);
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
123 idx = 0;
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
124 while (t && idx < l_x)
20735
418ae0cb752f Replace ++,-- with in-place operators for performance.
Rik <rik@octave.org>
parents: 20072
diff changeset
125 idx += 1;
18785
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
126 args = cell (1, 2+l_v);
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18785
diff changeset
127 args(1:2) = {nans_compare_equal, x{idx}};
18785
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
128 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
129
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
130 t = __isequal__ (args{:});
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
131 endwhile
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
132
18785
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
133 elseif (ischar (x) && all (cellfun ("isclass", varargin, "char")))
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
134 ## 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
135 ## row and test the rows.
18785
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
136 n_x = numel (x);
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
137 strings = cell (1, l_v);
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
138 for i = 1:l_v
18785
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
139 strings{i} = reshape (varargin{i}, 1, n_x);
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
140 endfor
18785
1f170b211be3 Make isequal matlab compatible when comparing char to numeric (bug #42408).
Rik <rik@octave.org>
parents: 18538
diff changeset
141 t = all (strcmp (reshape (x, 1, n_x), strings));
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
142
10260
14d5fee02b3b basic support for comparing function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9899
diff changeset
143 elseif (isa (x, "function_handle"))
14d5fee02b3b basic support for comparing function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9899
diff changeset
144 ## 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
145 t = all (cellfun ("eq", {x}, varargin));
10260
14d5fee02b3b basic support for comparing function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9899
diff changeset
146
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
147 else
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
148 ## Check the numeric types.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
149
10650
f0dc41c824ce Replace calls to deprecated functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
150 f_x = find (x);
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
151 l_f_x = length (f_x);
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
152 x = x(f_x);
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
153 for argn = 1:l_v
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
154 y = varargin{argn};
10650
f0dc41c824ce Replace calls to deprecated functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
155 f_y = find (y);
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
156
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
157 t = (l_f_x == length (f_y)) && all (f_x == f_y);
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20907
diff changeset
158 if (! t)
17278
79d4b6089968 Fix isequal for sparse matrix (bug #37321)
Stefan Mahr <dac922@gmx.de>
parents: 17176
diff changeset
159 break;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
160 endif
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
161
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
162 y = y(f_y);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
163 m = (x == y);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
164 t = all (m);
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
165
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20907
diff changeset
166 if (! t && nans_compare_equal)
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20907
diff changeset
167 t = isnan (x(! m)) && isnan (y(! m));
11125
8a8eb099502e Fix bug #31239 in isequalwithequalnans.m
Rik <octave@nomad.inbox5.com>
parents: 10650
diff changeset
168 endif
8a8eb099502e Fix bug #31239 in isequalwithequalnans.m
Rik <octave@nomad.inbox5.com>
parents: 10650
diff changeset
169
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20907
diff changeset
170 if (! t)
17278
79d4b6089968 Fix isequal for sparse matrix (bug #37321)
Stefan Mahr <dac922@gmx.de>
parents: 17176
diff changeset
171 break;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
172 endif
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
173 endfor
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
174
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
175 endif
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
176 endif
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
177
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
178 endfunction
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 17285
diff changeset
179