Mercurial > hg > octave-terminal
changeset 6157:045038e0108a
[project @ 2006-11-13 22:22:53 by jwe]
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,27 @@ +2006-11-13 John W. Eaton <jwe@octave.org> + + * 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 <hauberg@gmail.com> + + * 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 <jwe@octave.org> * plot/mesh.m: Use size_equal to compare dimensions.
--- a/scripts/general/__isequal__.m +++ b/scripts/general/__isequal__.m @@ -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.
--- a/scripts/general/bicubic.m +++ b/scripts/general/bicubic.m @@ -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
--- a/scripts/general/cart2pol.m +++ b/scripts/general/cart2pol.m @@ -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
--- a/scripts/general/cart2sph.m +++ b/scripts/general/cart2sph.m @@ -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
--- a/scripts/general/cumtrapz.m +++ b/scripts/general/cumtrapz.m @@ -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{:})) .*
--- a/scripts/general/interp2.m +++ b/scripts/general/interp2.m @@ -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
--- a/scripts/general/mod.m +++ b/scripts/general/mod.m @@ -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
--- a/scripts/general/pol2cart.m +++ b/scripts/general/pol2cart.m @@ -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
--- a/scripts/general/polyarea.m +++ b/scripts/general/polyarea.m @@ -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
--- a/scripts/general/rem.m +++ b/scripts/general/rem.m @@ -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
--- a/scripts/general/sph2cart.m +++ b/scripts/general/sph2cart.m @@ -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
--- a/scripts/general/trapz.m +++ b/scripts/general/trapz.m @@ -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{:})) .*
--- a/scripts/image/imshow.m +++ b/scripts/image/imshow.m @@ -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) = [];
--- a/scripts/image/rgb2ind.m +++ b/scripts/image/rgb2ind.m @@ -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
--- a/scripts/linear-algebra/cross.m +++ b/scripts/linear-algebra/cross.m @@ -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{:})),
--- a/scripts/linear-algebra/dot.m +++ b/scripts/linear-algebra/dot.m @@ -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);
--- a/scripts/miscellaneous/setfield.m +++ b/scripts/miscellaneous/setfield.m @@ -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
--- a/scripts/miscellaneous/xor.m +++ b/scripts/miscellaneous/xor.m @@ -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");
--- a/scripts/plot/__plr2__.m +++ b/scripts/plot/__plr2__.m @@ -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);
--- a/scripts/plot/__plr__.m +++ b/scripts/plot/__plr__.m @@ -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);
--- a/scripts/plot/contour.m +++ b/scripts/plot/contour.m @@ -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';
--- a/scripts/plot/plot3.m +++ b/scripts/plot/plot3.m @@ -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
--- a/scripts/polynomial/polyfit.m +++ b/scripts/polynomial/polyfit.m @@ -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
--- a/scripts/testfun/assert.m +++ b/scripts/testfun/assert.m @@ -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
--- a/src/ov.cc +++ b/src/ov.cc @@ -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;