annotate scripts/general/private/__isequal__.m @ 14868:5d3a684236b0

maint: Use Octave coding conventions for cuddling parentheses in scripts directory * lin2mu.m, loadaudio.m, wavread.m, accumarray.m, bicubic.m, celldisp.m, colon.m, cplxpair.m, dblquad.m, divergence.m, genvarname.m, gradient.m, int2str.m, interp1.m, interp1q.m, interp2.m, interpn.m, loadobj.m, nthargout.m, __isequal__.m, __splinen__.m, quadgk.m, quadl.m, quadv.m, rat.m, rot90.m, rotdim.m, saveobj.m, subsindex.m, triplequad.m, delaunay3.m, griddata.m, inpolygon.m, tsearchn.m, voronoi.m, get_first_help_sentence.m, which.m, gray2ind.m, pink.m, dlmwrite.m, strread.m, textread.m, textscan.m, housh.m, ishermitian.m, issymmetric.m, krylov.m, logm.m, null.m, rref.m, compare_versions.m, copyfile.m, dump_prefs.m, edit.m, fileparts.m, getappdata.m, isappdata.m, movefile.m, orderfields.m, parseparams.m, __xzip__.m, rmappdata.m, setappdata.m, swapbytes.m, unpack.m, ver.m, fminbnd.m, fminunc.m, fsolve.m, glpk.m, lsqnonneg.m, qp.m, sqp.m, configure_make.m, copy_files.m, describe.m, get_description.m, get_forge_pkg.m, install.m, installed_packages.m, is_architecture_dependent.m, load_package_dirs.m, print_package_description.m, rebuild.m, repackage.m, save_order.m, shell.m, allchild.m, ancestor.m, area.m, axes.m, axis.m, clabel.m, close.m, colorbar.m, comet.m, comet3.m, contour.m, cylinder.m, ezmesh.m, ezsurf.m, findobj.m, fplot.m, hist.m, isocolors.m, isonormals.m, isosurface.m, isprop.m, legend.m, mesh.m, meshz.m, pareto.m, pcolor.m, peaks.m, plot3.m, plotmatrix.m, plotyy.m, polar.m, print.m, __add_datasource__.m, __add_default_menu__.m, __axes_limits__.m, __bar__.m, __clabel__.m, __contour__.m, __errcomm__.m, __errplot__.m, __ezplot__.m, __file_filter__.m, __fltk_print__.m, __ghostscript__.m, __gnuplot_print__.m, __go_draw_axes__.m, __go_draw_figure__.m, __interp_cube__.m, __marching_cube__.m, __patch__.m, __pie__.m, __plt__.m, __print_parse_opts__.m, __quiver__.m, __scatter__.m, __stem__.m, __tight_eps_bbox__.m, __uigetdir_fltk__.m, __uigetfile_fltk__.m, __uiputfile_fltk__.m, quiver.m, quiver3.m, rectangle.m, refreshdata.m, ribbon.m, scatter.m, semilogy.m, shading.m, slice.m, subplot.m, surface.m, surfl.m, surfnorm.m, text.m, uigetfile.m, uiputfile.m, whitebg.m, deconv.m, mkpp.m, pchip.m, polyaffine.m, polyder.m, polygcd.m, polyout.m, polyval.m, ppint.m, ppjumps.m, ppval.m, residue.m, roots.m, spline.m, splinefit.m, addpref.m, getpref.m, setpref.m, ismember.m, setxor.m, arch_fit.m, arch_rnd.m, arch_test.m, autoreg_matrix.m, diffpara.m, fftconv.m, filter2.m, hanning.m, hurst.m, periodogram.m, triangle_sw.m, sinc.m, spectral_xdf.m, spencer.m, stft.m, synthesis.m, unwrap.m, yulewalker.m, bicgstab.m, gmres.m, pcg.m, pcr.m, __sprand_impl__.m, speye.m, spfun.m, sprandn.m, spstats.m, svds.m, treelayout.m, treeplot.m, bessel.m, factor.m, legendre.m, perms.m, primes.m, magic.m, toeplitz.m, corr.m, cov.m, mean.m, median.m, mode.m, qqplot.m, quantile.m, ranks.m, zscore.m, logistic_regression_likelihood.m, bartlett_test.m, chisquare_test_homogeneity.m, chisquare_test_independence.m, kolmogorov_smirnov_test.m, run_test.m, u_test.m, wilcoxon_test.m, z_test.m, z_test_2.m, bin2dec.m, dec2base.m, mat2str.m, strcat.m, strchr.m, strjust.m, strtok.m, substr.m, untabify.m, assert.m, demo.m, example.m, fail.m, speed.m, test.m, now.m: Use Octave coding conventions for cuddling parentheses in scripts directory.
author Rik <octave@nomad.inbox5.com>
date Tue, 17 Jul 2012 07:08:39 -0700
parents 72c96de7a403
children abf384f5d243
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 12931
diff changeset
1 ## Copyright (C) 2000-2012 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
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
36 ## 2. If x is of the struct, cell, list or char class, for each
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
37 ## argument after x, determine whether it has the same class
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
38 ## and size as x.
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
39 ## Otherwise, for each argument after x, verify that it is not
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
40 ## of the struct, cell, list or char class, and that it has
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
41 ## the same size as x.
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)
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
44 ## b. cell/list compare each member by order (recursive)
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
45 ## c. char compare each member with strcmp
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
46 ## d. <other> compare each nonzero member, and assume NaN == NaN
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
47 ## if nans_compare_equal is nonzero.
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
48
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
49 function t = __isequal__ (nans_compare_equal, x, varargin)
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 if (nargin < 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 6023
diff changeset
52 print_usage ();
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
53 endif
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
54
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
55 l_v = nargin - 2;
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
56
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
57 ## Generic tests.
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
58
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 6157
diff changeset
59 ## All arguments must either be of the same class or they must be
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 6157
diff changeset
60 ## numeric values.
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
61 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
62 cellfun ("class", varargin, "uniformoutput", false)))
9841
6f1ea8241c99 make isnumeric yield false on logicals
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
63 || ((isnumeric (x) || islogical (x))
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
64 && all (cellfun ("isnumeric", varargin)
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
65 | cellfun ("islogical", varargin))));
6609
30891d1d0c86 [project @ 2007-05-09 02:12:04 by jwe]
jwe
parents: 6157
diff changeset
66
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
67 if (t)
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
68 ## Test that everything has the same number of dimensions.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
69 s_x = size (x);
11191
01ddaedd6ad5 Reverse changeset b1f4bdc276b6. Use all lower case for "uniformoutput" option.
Rik <octave@nomad.inbox5.com>
parents: 11126
diff changeset
70 s_v = cellfun (@size, varargin, "uniformoutput", false);
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
71 t = all (length (s_x) == cellfun ("length", s_v));
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
72 endif
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
73
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
74 if (t)
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
75 ## Test that everything is the same size since it has the same
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
76 ## dimensionality.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
77 l_x = length (s_x);
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
78 s_v = reshape ([s_v{:}], length (s_x), []);
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
79 idx = 0;
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
80 while (t && idx < l_x)
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
81 idx++;
11126
304b0ed4ca56 __isequal__.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 11125
diff changeset
82 t = all (s_x(idx) == s_v(idx,:));
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
83 endwhile
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
84 endif
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
85
11459
990c9cb52e5f __isequal__: compare objects as if they are structures
John W. Eaton <jwe@octave.org>
parents: 11191
diff changeset
86 ## From here on, compare objects as if they were structures.
990c9cb52e5f __isequal__: compare objects as if they are structures
John W. Eaton <jwe@octave.org>
parents: 11191
diff changeset
87 if (isobject (x))
11475
caf1fd72f587 __isequal__: avoid possible overloading of struct function for objects
John W. Eaton <jwe@octave.org>
parents: 11459
diff changeset
88 x = builtin ("struct", x);
caf1fd72f587 __isequal__: avoid possible overloading of struct function for objects
John W. Eaton <jwe@octave.org>
parents: 11459
diff changeset
89 varargin = cellfun (@(x) builtin ("struct", x), varargin,
caf1fd72f587 __isequal__: avoid possible overloading of struct function for objects
John W. Eaton <jwe@octave.org>
parents: 11459
diff changeset
90 "uniformoutput", false);
11459
990c9cb52e5f __isequal__: compare objects as if they are structures
John W. Eaton <jwe@octave.org>
parents: 11191
diff changeset
91 endif
990c9cb52e5f __isequal__: compare objects as if they are structures
John W. Eaton <jwe@octave.org>
parents: 11191
diff changeset
92
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
93 if (t)
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
94 ## Check individual classes.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
95 if (isstruct (x))
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
96 ## Test the number of fields.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
97 fn_x = fieldnames (x);
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
98 l_fn_x = length (fn_x);
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
99 fn_v = cellfun ("fieldnames", varargin, "uniformoutput", false);
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
100 t = all (l_fn_x == cellfun ("length", fn_v));
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
101
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
102 ## Test that all the names are equal.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
103 idx = 0;
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
104 s_fn_x = sort (fn_x);
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
105 while (t && idx < l_v)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
106 idx++;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
107 ## We'll allow the fieldnames to be in a different order.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
108 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
109 endwhile
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
110
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
111 idx = 0;
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
112 while (t && idx < l_fn_x)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
113 ## Test that all field values are equal.
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
114 idx++;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
115 args = {nans_compare_equal, {x.(fn_x{idx})}};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
116 for argn = 1:l_v
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
117 args{argn+2} = {varargin{argn}.(fn_x{idx})};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
118 endfor
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
119 ## Minimize function calls by calling for all the arguments at
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
120 ## once.
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
121 t = __isequal__ (args{:});
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
122 endwhile
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
123
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
124 elseif (iscell (x))
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
125 ## Check that each element of a cell is equal.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
126 l_x = numel (x);
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
127 idx = 0;
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
128 while (t && idx < l_x)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
129 idx++;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
130 args = {nans_compare_equal, x{idx}};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
131 for p = 1:l_v
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
132 args{p+2} = varargin{p}{idx};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
133 endfor
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
134 t = __isequal__ (args{:});
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
135 endwhile
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
136
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
137 elseif (ischar (x))
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
138
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
139 ## 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
140 ## row and test the rows.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
141 for i = 1:l_v
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
142 strings{i} = reshape (varargin{i}, 1, []);
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
143 endfor
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
144 t = all (strcmp (reshape (x, 1, []), strings));
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
145
10260
14d5fee02b3b basic support for comparing function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9899
diff changeset
146 elseif (isa (x, "function_handle"))
14d5fee02b3b basic support for comparing function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9899
diff changeset
147
14d5fee02b3b basic support for comparing function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9899
diff changeset
148 ## 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
149 t = all (cellfun ("eq", {x}, varargin));
10260
14d5fee02b3b basic support for comparing function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9899
diff changeset
150
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
151 else
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
152 ## Check the numeric types.
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
153
10650
f0dc41c824ce Replace calls to deprecated functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
154 f_x = find (x);
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
155 l_f_x = length (f_x);
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
156 x = x(f_x);
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
157 for argn = 1:l_v
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
158 y = varargin{argn};
10650
f0dc41c824ce Replace calls to deprecated functions.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
159 f_y = find (y);
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
160
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
161 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
162 if (!t)
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
163 return;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
164 endif
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
165
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
166 y = y(f_y);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
167 m = (x == y);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
168 t = all (m);
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
169
11126
304b0ed4ca56 __isequal__.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 11125
diff changeset
170 if (!t && nans_compare_equal)
304b0ed4ca56 __isequal__.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 11125
diff changeset
171 t = isnan (x(!m)) && isnan (y(!m));
11125
8a8eb099502e Fix bug #31239 in isequalwithequalnans.m
Rik <octave@nomad.inbox5.com>
parents: 10650
diff changeset
172 endif
8a8eb099502e Fix bug #31239 in isequalwithequalnans.m
Rik <octave@nomad.inbox5.com>
parents: 10650
diff changeset
173
8a8eb099502e Fix bug #31239 in isequalwithequalnans.m
Rik <octave@nomad.inbox5.com>
parents: 10650
diff changeset
174 if (!t)
11126
304b0ed4ca56 __isequal__.m: style fixes
John W. Eaton <jwe@octave.org>
parents: 11125
diff changeset
175 return;
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10293
diff changeset
176 endif
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
177 endfor
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
178
6130
6eba20084f8f [project @ 2006-11-01 16:54:04 by jwe]
jwe
parents: 6046
diff changeset
179 endif
5549
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
180 endif
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
181
6db3a5df1eab [project @ 2005-11-30 03:15:19 by jwe]
jwe
parents:
diff changeset
182 endfunction