Mercurial > hg > octave-lyh
changeset 7600:24abf5a702d9
Chop trailing singletons in min/max functions
author | David Bateman <dbateman@free.fr> |
---|---|
date | Tue, 18 Mar 2008 20:27:50 -0400 |
parents | 461d6bfba85a |
children | 8a939b217863 |
files | liboctave/CNDArray.cc liboctave/ChangeLog liboctave/dNDArray.cc liboctave/intNDArray.cc src/ChangeLog src/DLD-FUNCTIONS/minmax.cc test/test_arith.m |
diffstat | 7 files changed, 83 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/CNDArray.cc +++ b/liboctave/CNDArray.cc @@ -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; }
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,5 +1,9 @@ 2008-03-18 David Bateman <dbateman@free.fr> + * dNDArray.cc (NDArray::min, NDArraymax): chop trailing singletons. + * CNDarray.cc (ComplexNDArray::min, CompelxNDArray::max): ditto. + * intNDarray.cc (intNDArray<T>::min, intNDArray<T>::max): ditto. + * Array.cc (Array<T>::index): Don't short_freeze on index with fewer dimensions than the array only if the last dimension is empty.
--- a/liboctave/dNDArray.cc +++ b/liboctave/dNDArray.cc @@ -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; }
--- a/liboctave/intNDArray.cc +++ b/liboctave/intNDArray.cc @@ -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; }
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2008-03-18 David Bateman <dbateman@free.fr> + + * DLD-FUNCTIONS/minmax.cc: 64-bit indexing fix. + 2008-03-13 John W. Eaton <jwe@octave.org> * ov-usr-fcn.cc (octave_user_function::octave_user_function):
--- a/src/DLD-FUNCTIONS/minmax.cc +++ b/src/DLD-FUNCTIONS/minmax.cc @@ -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<double> (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<double> (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 <Invalid call to min.*> min (); + +%% test/octave.test/arith/min-4.m +%!error <Invalid call to min.*> 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 <Invalid call to max.*> max (); + +%% test/octave.test/arith/max-4.m +%!error <Invalid call to max.*> 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++ ***
--- a/test/test_arith.m +++ b/test/test_arith.m @@ -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 <Invalid call to max.*> max (); - -%% test/octave.test/arith/max-4.m -%!error <Invalid call to max.*> 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 <Invalid call to min.*> min (); - -%% test/octave.test/arith/min-4.m -%!error <Invalid call to min.*> 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));