# HG changeset patch # User David Bateman # Date 1205886470 14400 # Node ID 24abf5a702d93057c7a788db2a98a624c1eb5802 # Parent 461d6bfba85ac049339c6979ae7f79141982d578 Chop trailing singletons in min/max functions diff -r 461d6bfba85a -r 24abf5a702d9 liboctave/CNDArray.cc --- a/liboctave/CNDArray.cc Tue Mar 18 16:39:25 2008 -0400 +++ b/liboctave/CNDArray.cc Tue Mar 18 20:27:50 2008 -0400 @@ -771,6 +771,9 @@ } } + result.chop_trailing_singletons (); + idx_arg.chop_trailing_singletons (); + return result; } @@ -863,6 +866,9 @@ } } + result.chop_trailing_singletons (); + idx_arg.chop_trailing_singletons (); + return result; } diff -r 461d6bfba85a -r 24abf5a702d9 liboctave/ChangeLog --- a/liboctave/ChangeLog Tue Mar 18 16:39:25 2008 -0400 +++ b/liboctave/ChangeLog Tue Mar 18 20:27:50 2008 -0400 @@ -1,5 +1,9 @@ 2008-03-18 David Bateman + * dNDArray.cc (NDArray::min, NDArraymax): chop trailing singletons. + * CNDarray.cc (ComplexNDArray::min, CompelxNDArray::max): ditto. + * intNDarray.cc (intNDArray::min, intNDArray::max): ditto. + * Array.cc (Array::index): Don't short_freeze on index with fewer dimensions than the array only if the last dimension is empty. diff -r 461d6bfba85a -r 24abf5a702d9 liboctave/dNDArray.cc --- a/liboctave/dNDArray.cc Tue Mar 18 16:39:25 2008 -0400 +++ b/liboctave/dNDArray.cc Tue Mar 18 20:27:50 2008 -0400 @@ -742,6 +742,9 @@ idx_arg.elem (i) = xisnan (tmp_max) ? 0 : idx_j; } + result.chop_trailing_singletons (); + idx_arg.chop_trailing_singletons (); + return result; } @@ -817,6 +820,9 @@ idx_arg.elem (i) = xisnan (tmp_min) ? 0 : idx_j; } + result.chop_trailing_singletons (); + idx_arg.chop_trailing_singletons (); + return result; } diff -r 461d6bfba85a -r 24abf5a702d9 liboctave/intNDArray.cc --- a/liboctave/intNDArray.cc Tue Mar 18 16:39:25 2008 -0400 +++ b/liboctave/intNDArray.cc Tue Mar 18 20:27:50 2008 -0400 @@ -327,6 +327,9 @@ idx_arg.elem (i) = idx_j; } + result.chop_trailing_singletons (); + idx_arg.chop_trailing_singletons (); + return result; } @@ -394,6 +397,9 @@ idx_arg.elem (i) = idx_j; } + result.chop_trailing_singletons (); + idx_arg.chop_trailing_singletons (); + return result; } diff -r 461d6bfba85a -r 24abf5a702d9 src/ChangeLog --- a/src/ChangeLog Tue Mar 18 16:39:25 2008 -0400 +++ b/src/ChangeLog Tue Mar 18 20:27:50 2008 -0400 @@ -1,3 +1,7 @@ +2008-03-18 David Bateman + + * DLD-FUNCTIONS/minmax.cc: 64-bit indexing fix. + 2008-03-13 John W. Eaton * ov-usr-fcn.cc (octave_user_function::octave_user_function): diff -r 461d6bfba85a -r 24abf5a702d9 src/DLD-FUNCTIONS/minmax.cc --- a/src/DLD-FUNCTIONS/minmax.cc Tue Mar 18 16:39:25 2008 -0400 +++ b/src/DLD-FUNCTIONS/minmax.cc Tue Mar 18 20:27:50 2008 -0400 @@ -108,7 +108,7 @@ for (octave_idx_type i = 0; i < len; i++) \ { \ OCTAVE_QUIT; \ - int tmp = index.elem (i) + 1; \ + octave_idx_type tmp = index.elem (i) + 1; \ idx.elem (i) = (tmp <= 0) \ ? nan_val : static_cast (tmp); \ } \ @@ -254,7 +254,7 @@ for (octave_idx_type i = 0; i < len; i++) \ { \ OCTAVE_QUIT; \ - int tmp = index.elem (i) + 1; \ + octave_idx_type tmp = index.elem (i) + 1; \ idx.elem (i) = (tmp <= 0) \ ? nan_val : static_cast (tmp); \ } \ @@ -593,6 +593,33 @@ MINMAX_BODY (min); } +/* + +%% test/octave.test/arith/min-1.m +%!assert (min ([1, 4, 2, 3]) == 1); +%!assert (min ([1; -10; 5; -2]) == -10); + +%% test/octave.test/arith/min-2.m +%!assert(all (min ([4, i; -2, 2]) == [-2, i])); + +%% test/octave.test/arith/min-3.m +%!error min (); + +%% test/octave.test/arith/min-4.m +%!error min (1, 2, 3, 4); + +%!test +%! x = reshape (1:8,[2,2,2]); +%! assert (max (x,[],1), reshape ([2, 4, 6, 8], [1,2,2])); +%! assert (max (x,[],2), reshape ([3, 4, 7, 8], [2,1,2])); +%! [y, i ] = max (x, [], 3); +%! assert (y, [5, 7; 6, 8]); +%! assert (ndims(y), 2); +%! assert (i, [2, 2; 2, 2]); +%! assert (ndims(i), 2); + +*/ + DEFUN_DLD (max, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Mapping Function} {} max (@var{x}, @var{y}, @var{dim})\n\ @@ -640,6 +667,34 @@ MINMAX_BODY (max); } +/* + +%% test/octave.test/arith/max-1.m +%!assert (max ([1, 4, 2, 3]) == 4); +%!assert (max ([1; -10; 5; -2]) == 5); + +%% test/octave.test/arith/max-2.m +%!assert(all (max ([4, i 4.999; -2, 2, 3+4i]) == [4, 2, 3+4i])); + +%% test/octave.test/arith/max-3.m +%!error max (); + +%% test/octave.test/arith/max-4.m +%!error max (1, 2, 3, 4); + +%!test +%! x = reshape (1:8,[2,2,2]); +%! assert (min (x,[],1), reshape ([1, 3, 5, 7], [1,2,2])); +%! assert (min (x,[],2), reshape ([1, 2, 5, 6], [2,1,2])); +%! [y, i ] = min (x, [], 3); +%! assert (y, [1, 3; 2, 4]); +%! assert (ndims(y), 2); +%! assert (i, [1, 1; 1, 1]); +%! assert (ndims(i), 2); + + +*/ + /* ;;; Local Variables: *** ;;; mode: C++ *** diff -r 461d6bfba85a -r 24abf5a702d9 test/test_arith.m --- a/test/test_arith.m Tue Mar 18 16:39:25 2008 -0400 +++ b/test/test_arith.m Tue Mar 18 20:27:50 2008 -0400 @@ -135,32 +135,6 @@ %! s.a = 1; %! fail("gcd (s)"); -%% test/octave.test/arith/max-1.m -%!assert (max ([1, 4, 2, 3]) == 4); -%!assert (max ([1; -10; 5; -2]) == 5); - -%% test/octave.test/arith/max-2.m -%!assert(all (max ([4, i 4.999; -2, 2, 3+4i]) == [4, 2, 3+4i])); - -%% test/octave.test/arith/max-3.m -%!error max (); - -%% test/octave.test/arith/max-4.m -%!error max (1, 2, 3, 4); - -%% test/octave.test/arith/min-1.m -%!assert (min ([1, 4, 2, 3]) == 1); -%!assert (min ([1; -10; 5; -2]) == -10); - -%% test/octave.test/arith/min-2.m -%!assert(all (min ([4, i; -2, 2]) == [-2, i])); - -%% test/octave.test/arith/min-3.m -%!error min (); - -%% test/octave.test/arith/min-4.m -%!error min (1, 2, 3, 4); - %% test/octave.test/arith/round-1.m %!assert((round (1) == 1 && round (1.1) == 1 && round (5.5) == 6 %! && round (i) == i && round (2.5+3.5i) == 3+4i && round (-2.6) == -3));