# HG changeset patch # User jwe # Date 1163456574 0 # Node ID 045038e0108a521a1b3c1042668d78dc1596f7f8 # Parent a46f14cdbecd78b0c9cb5002e677b53d2ec98f70 [project @ 2006-11-13 22:22:53 by jwe] diff -r a46f14cdbecd -r 045038e0108a scripts/ChangeLog --- a/scripts/ChangeLog Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/ChangeLog Mon Nov 13 22:22:54 2006 +0000 @@ -1,3 +1,27 @@ +2006-11-13 John W. Eaton + + * miscellaneous/substruct.m: New function. + + * testfun/assert.m: Force orientation to match when comparing + struct elements. + + * general/__isequal__.m: Avoid assignment of comma-separated lists + when comparing structs. + +2006-11-13 Søren Hauberg + + * scripts/general/bicubic.m, scripts/general/cart2pol.m + scripts/general/cart2sph.m, scripts/plot/contour.m, + scripts/linear-algebra/cross.m, scripts/general/cumtrapz.m, + scripts/linear-algebra/dot.m, scripts/image/imshow.m, + scripts/general/interp2.m, scripts/general/mod.m, + scripts/plot/plot3.m, scripts/plot/__plr2__.m, + scripts/plot/__plr__.m, scripts/general/pol2cart.m, + scripts/general/polyarea.m, scripts/polynomial/polyfit.m, + scripts/general/rem.m, scripts/image/rgb2ind.m, + scripts/general/sph2cart.m, scripts/general/trapz.m, + scripts/miscellaneous/xor.m: Use size_equal + 2006-11-13 John W. Eaton * plot/mesh.m: Use size_equal to compare dimensions. diff -r a46f14cdbecd -r 045038e0108a scripts/general/__isequal__.m --- a/scripts/general/__isequal__.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/general/__isequal__.m Mon Nov 13 22:22:54 2006 +0000 @@ -104,9 +104,9 @@ while (t && idx < l_fn_x) ## Test that all field values are equal. idx++; - args = {nans_compare_equal, x.(fn_x{idx})}; + args = {nans_compare_equal, {x.(fn_x{idx})}}; for argn = 1:l_v - args{argn+2} = varargin{argn}.(fn_x{idx}); + args{argn+2} = {varargin{argn}.(fn_x{idx})}; endfor ## Minimize function calls by calling for all the arguments at ## once. diff -r a46f14cdbecd -r 045038e0108a scripts/general/bicubic.m --- a/scripts/general/bicubic.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/general/bicubic.m Mon Nov 13 22:22:54 2006 +0000 @@ -70,7 +70,7 @@ if (rz != length (Y) || cz != length (X)) error ("length of X and Y must match the size of Z"); endif - elseif (size(X) == size(Y) && size(X) == size(Z)) + elseif (size_equal (X, Y) && size_equal (X, Z)) X = X(1,:); Y = Y(:,1); else diff -r a46f14cdbecd -r 045038e0108a scripts/general/cart2pol.m --- a/scripts/general/cart2pol.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/general/cart2pol.m Mon Nov 13 22:22:54 2006 +0000 @@ -41,7 +41,7 @@ endif if ((! (ismatrix (X) && ismatrix (Y))) - || (size (X) != size (Y)) + || (! size_equal (X, Y)) || (nargin == 3 && (! (size (X) == size (Z) && ismatrix (Z))))) error ("cart2pol: arguments must be matrices of same size"); endif diff -r a46f14cdbecd -r 045038e0108a scripts/general/cart2sph.m --- a/scripts/general/cart2sph.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/general/cart2sph.m Mon Nov 13 22:22:54 2006 +0000 @@ -37,8 +37,8 @@ endif if ((! (ismatrix (X) && ismatrix (Y) && ismatrix (Z))) - || size (X) != size (Y) - || size (X) != size (Z)) + || (! size_equal (X, Y)) + || (! size_equal (X, Z)) error ("cart2sph: arguments must be matrices of same size"); endif diff -r a46f14cdbecd -r 045038e0108a scripts/general/cumtrapz.m --- a/scripts/general/cumtrapz.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/general/cumtrapz.m Mon Nov 13 22:22:54 2006 +0000 @@ -53,7 +53,7 @@ have_dim = true; endif if (nargin == 2) - if (size (x) != size (y) && isscalar (y)) + if (! size_equal (x, y) && isscalar (y)) dim = y; have_dim = true; else @@ -90,7 +90,7 @@ if (! have_x) z = 0.5 * cumsum (x(idx1{:}) + x(idx2{:}), dim); else - if (size (x) != size (y)) + if (! size_equal (x, y)) error ("cumtrapz: x and y must have same shape"); endif z = 0.5 * cumsum ((x(idx1{:}) - x(idx2{:})) .* diff -r a46f14cdbecd -r 045038e0108a scripts/general/interp2.m --- a/scripts/general/interp2.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/general/interp2.m Mon Nov 13 22:22:54 2006 +0000 @@ -164,10 +164,10 @@ ## If X and Y vectors produce a grid from them if (isvector (X) && isvector (Y)) [X, Y] = meshgrid (X, Y); - elseif (! all (size (X) == size (Y))) + elseif (! size_equal (X, Y)) error ("X and Y must be matrices of same size"); endif - if (any (size (X) != size (Z))) + if (! size_equal (X, Z)) error ("X and Y size must match Z dimensions"); endif @@ -175,7 +175,7 @@ if ((rows (XI) == 1 && columns (YI) == 1) || (columns (XI) == 1 && rows (YI) == 1)) [XI, YI] = meshgrid (XI, YI); - elseif (any (size (XI) != size (YI))) + elseif (! size_equal (XI, YI)) error ("XI and YI must be matrices of same size"); endif diff -r a46f14cdbecd -r 045038e0108a scripts/general/mod.m --- a/scripts/general/mod.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/general/mod.m Mon Nov 13 22:22:54 2006 +0000 @@ -44,8 +44,7 @@ print_usage (); endif - if (((ndims (x) != ndims (y)) || any (size (x) != size (y))) && - ! (isscalar (x) || isscalar (y))) + if (! size_equal (x, y) && ! (isscalar (x) || isscalar (y))) error ("mod: argument sizes must agree"); endif diff -r a46f14cdbecd -r 045038e0108a scripts/general/pol2cart.m --- a/scripts/general/pol2cart.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/general/pol2cart.m Mon Nov 13 22:22:54 2006 +0000 @@ -41,8 +41,8 @@ endif if ((! (ismatrix (Theta) && ismatrix (R))) - || (size (Theta) != size (R)) - || (nargin == 3 && (! (size (R) == size (Z) && ismatrix (Z))))) + || (! size_equal (Theta, R)) + || (nargin == 3 && ! (size_equal (R, Z) && ismatrix (Z)))) error ("pol2cart: arguments must be matrices of same size"); endif diff -r a46f14cdbecd -r 045038e0108a scripts/general/polyarea.m --- a/scripts/general/polyarea.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/general/polyarea.m Mon Nov 13 22:22:54 2006 +0000 @@ -51,7 +51,7 @@ function a = polyarea (x, y, dim) if (nargin != 2 && nargin != 3) print_usage (); - elseif (ndims (x) == ndims (y) && size (x) == size (y)) + elseif (size_equal (x, y)) if (nargin == 2) a = abs (sum (x .* (shift (y, -1) - shift (y, 1)))) / 2; else diff -r a46f14cdbecd -r 045038e0108a scripts/general/rem.m --- a/scripts/general/rem.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/general/rem.m Mon Nov 13 22:22:54 2006 +0000 @@ -39,8 +39,7 @@ print_usage (); endif - if (((ndims (x) != ndims (y)) || any (size (x) != size (y))) && - ! (isscalar (x) || isscalar (y))) + if (! size_equal (x, y) && ! (isscalar (x) || isscalar (y))) error ("rem: argument sizes must agree"); endif diff -r a46f14cdbecd -r 045038e0108a scripts/general/sph2cart.m --- a/scripts/general/sph2cart.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/general/sph2cart.m Mon Nov 13 22:22:54 2006 +0000 @@ -37,8 +37,8 @@ endif if ((! (ismatrix (Theta) && ismatrix (Phi) && ismatrix (R))) - || size (Theta) != size (Phi) - || size (Theta) != size (R)) + || (! size_equal (Theta, Phi)) + || (! size_equal (Theta, R))) error ("sph2cart: arguments must be matrices of same size"); endif diff -r a46f14cdbecd -r 045038e0108a scripts/general/trapz.m --- a/scripts/general/trapz.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/general/trapz.m Mon Nov 13 22:22:54 2006 +0000 @@ -53,7 +53,7 @@ have_dim = true; endif if (nargin == 2) - if (size (x) != size (y) && isscalar (y)) + if (! size_equal (x, y) && isscalar (y)) dim = y; have_dim = true; else @@ -90,7 +90,7 @@ if (! have_x) z = 0.5 * sum (x(idx1{:}) + x(idx2{:}), dim); else - if (size (x) != size (y)) + if (! size_equal (x, y)) error ("cumtrapz: x and y must have same shape"); endif z = 0.5 * sum ((x(idx1{:}) - x(idx2{:})) .* diff -r a46f14cdbecd -r 045038e0108a scripts/image/imshow.m --- a/scripts/image/imshow.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/image/imshow.m Mon Nov 13 22:22:54 2006 +0000 @@ -75,8 +75,8 @@ && ndims (im) == 2 && ndims (varargin{1}) == 2 && ndims (varargin{2}) == 2 - && size (im) == size (varargin{1}) - && size (im) == size (varargin{2})) + && size_equal (im, varargin{1}) + && size_equal (im, varargin{2})) im(:,:,3) = varargin{2}; im(:,:,2) = varargin{1}; varargin(1:2) = []; diff -r a46f14cdbecd -r 045038e0108a scripts/image/rgb2ind.m --- a/scripts/image/rgb2ind.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/image/rgb2ind.m Mon Nov 13 22:22:54 2006 +0000 @@ -47,7 +47,7 @@ endif endif - if (size (R) != size (G) || size (R) != size (B)) + if (! size_equal (R, G) || ! size_equal (R, B)) error ("rgb2ind: arguments must all have the same size"); endif diff -r a46f14cdbecd -r 045038e0108a scripts/linear-algebra/cross.m --- a/scripts/linear-algebra/cross.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/linear-algebra/cross.m Mon Nov 13 22:22:54 2006 +0000 @@ -80,7 +80,7 @@ idx2(dim) = 2; idx3(dim) = 3; - if (size (x) == size (y)) + if (size_equal (x, y)) z = cat (dim, (x(idx2{:}) .* y(idx3{:}) - x(idx3{:}) .* y(idx2{:})), (x(idx3{:}) .* y(idx1{:}) - x(idx1{:}) .* y(idx3{:})), diff -r a46f14cdbecd -r 045038e0108a scripts/linear-algebra/dot.m --- a/scripts/linear-algebra/dot.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/linear-algebra/dot.m Mon Nov 13 22:22:54 2006 +0000 @@ -40,12 +40,12 @@ if isvector (y) y = y(:); endif - if (size (x) != size (y)) + if (! size_equal (x, y)) error ("dot: sizes of arguments must match") endif z = sum(x .* y); else - if (size (x) != size (y)) + if (! size_equal (x, y)) error ("dot: sizes of arguments must match") endif z = sum(x .* y, dim); diff -r a46f14cdbecd -r 045038e0108a scripts/miscellaneous/setfield.m --- a/scripts/miscellaneous/setfield.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/miscellaneous/setfield.m Mon Nov 13 22:22:54 2006 +0000 @@ -18,7 +18,7 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn {Built-in Function} {[@var{k1},..., @var{v1}] =} setfield (@var{s}, @var{k1}, @var{v1}, @dots{}) +## @deftypefn {Function File} {[@var{k1},..., @var{v1}] =} setfield (@var{s}, @var{k1}, @var{v1}, @dots{}) ## Set field members in a structure. ## ## @example diff -r a46f14cdbecd -r 045038e0108a scripts/miscellaneous/xor.m --- a/scripts/miscellaneous/xor.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/miscellaneous/xor.m Mon Nov 13 22:22:54 2006 +0000 @@ -32,7 +32,7 @@ function z = xor (x, y) if (nargin == 2) - if (isscalar (x) || isscalar (y) || size (x) == size (y)) + if (isscalar (x) || isscalar (y) || size_equal (x, y)) z = logical ((x | y) - (x & y)); else error ("xor: x and y must be of common size or scalars"); diff -r a46f14cdbecd -r 045038e0108a scripts/plot/__plr2__.m --- a/scripts/plot/__plr2__.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/plot/__plr2__.m Mon Nov 13 22:22:54 2006 +0000 @@ -107,7 +107,7 @@ y = diag_r * sin (theta); __plt__ ("polar", x, y, fmt); elseif (ismatrix (rho)) - if (size (rho) != size (theta)) + if (! size_equal (rho, theta)) error ("__plr2__: matrix dimensions must match"); endif x = rho .* cos (theta); diff -r a46f14cdbecd -r 045038e0108a scripts/plot/__plr__.m --- a/scripts/plot/__plr__.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/plot/__plr__.m Mon Nov 13 22:22:54 2006 +0000 @@ -121,7 +121,7 @@ y = diag_r * sin (theta); __plt__ ("polar", x, y, fmt); elseif (ismatrix (rho)) - if (size (rho) != size (theta)) + if (! size_equal (rho, theta)) error ("polar: matrix dimensions must match"); endif x = rho .* cos (theta); diff -r a46f14cdbecd -r 045038e0108a scripts/plot/contour.m --- a/scripts/plot/contour.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/plot/contour.m Mon Nov 13 22:22:54 2006 +0000 @@ -92,7 +92,7 @@ endif else z_size = size (z); - if (z_size == size (x) && z_size == size (y)) + if (size_equal (z, x) && size_equal (z, y)) nc = 3*z_size(1); zz = zeros (z_size(2), nc); zz(:,1:3:nc) = x'; diff -r a46f14cdbecd -r 045038e0108a scripts/plot/plot3.m --- a/scripts/plot/plot3.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/plot/plot3.m Mon Nov 13 22:22:54 2006 +0000 @@ -213,7 +213,7 @@ endif endif - if (any (size (x) != size (y)) || any (size (x) != size (z))) + if (! size_equal (x, y) || ! size_equal (x, z)) error ("plot3: x, y, and z must have the same shape"); endif @@ -251,7 +251,7 @@ endif endif - if (any (size (x) != size (y)) || any (size (x) != size (z))) + if (! size_equal (x, y) || ! size_equal (x, z)) error ("plot3: x, y, and z must have the same shape"); endif @@ -303,7 +303,7 @@ endif endif - if (any (size (x) != size (y)) || any (size (x) != size (z))) + if (! size_equal (x, y) || ! size_equal (x, z)) error ("plot3: x, y, and z must have the same shape"); endif diff -r a46f14cdbecd -r 045038e0108a scripts/polynomial/polyfit.m --- a/scripts/polynomial/polyfit.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/polynomial/polyfit.m Mon Nov 13 22:22:54 2006 +0000 @@ -64,7 +64,7 @@ print_usage (); endif - if (! (isvector (x) && isvector (y) && size (x) == size (y))) + if (! (isvector (x) && isvector (y) && size_equal (x, y))) error ("polyfit: x and y must be vectors of the same size"); endif diff -r a46f14cdbecd -r 045038e0108a scripts/testfun/assert.m --- a/scripts/testfun/assert.m Mon Nov 13 19:20:23 2006 +0000 +++ b/scripts/testfun/assert.m Mon Nov 13 22:22:54 2006 +0000 @@ -110,10 +110,11 @@ for [v,k] = cond if !struct_contains(expected,k), error; endif if empty, v = cell(1,0); endif - if normal, v = {v}; endif - assert(v,{expected.(k)},tol); + if normal, v = {v}; else v = v(:)'; endif + assert(v,{expected.(k)},tol) endfor catch + "catch" iserror = 1; end endif diff -r a46f14cdbecd -r 045038e0108a src/ov.cc --- a/src/ov.cc Mon Nov 13 19:20:23 2006 +0000 +++ b/src/ov.cc Mon Nov 13 22:22:54 2006 +0000 @@ -1962,6 +1962,7 @@ are @samp{\"()\"}, @samp{\"@{@}\", and @samp{\".\"}.\n\ The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ of index values.\n\ +@seealso{subsasgn, substruct}\n\ @end deftypefn") { octave_value_list retval; @@ -1993,6 +1994,7 @@ are @samp{\"()\"}, @samp{\"@{@}\", and @samp{\".\"}.\n\ The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ of index values.\n\ +@seealso{subsref, substruct}\n\ @end deftypefn") { octave_value retval;