changeset 11700:a255ceb8e416 release-3-0-x

Chop trailing singletons in min/max functions
author David Bateman <dbateman@free.fr>
date Tue, 18 Mar 2008 20:47:40 -0400
parents 1e9ce581998e
children b537a643a7cf
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	Tue Mar 18 16:21:34 2008 -0400
+++ b/liboctave/CNDArray.cc	Tue Mar 18 20:47:40 2008 -0400
@@ -770,6 +770,9 @@
 	}
     }
 
+  result.chop_trailing_singletons ();
+  idx_arg.chop_trailing_singletons ();
+
   return result;
 }
 
@@ -862,6 +865,9 @@
 	}
     }
 
+  result.chop_trailing_singletons ();
+  idx_arg.chop_trailing_singletons ();
+
   return result;
 }
 
--- a/liboctave/ChangeLog	Tue Mar 18 16:21:34 2008 -0400
+++ b/liboctave/ChangeLog	Tue Mar 18 20:47:40 2008 -0400
@@ -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	Tue Mar 18 16:21:34 2008 -0400
+++ b/liboctave/dNDArray.cc	Tue Mar 18 20:47:40 2008 -0400
@@ -741,6 +741,9 @@
       idx_arg.elem (i) = xisnan (tmp_max) ? 0 : idx_j;
     }
 
+  result.chop_trailing_singletons ();
+  idx_arg.chop_trailing_singletons ();
+
   return result;
 }
 
@@ -816,6 +819,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	Tue Mar 18 16:21:34 2008 -0400
+++ b/liboctave/intNDArray.cc	Tue Mar 18 20:47:40 2008 -0400
@@ -293,6 +293,9 @@
       idx_arg.elem (i) = idx_j;
     }
 
+  result.chop_trailing_singletons ();
+  idx_arg.chop_trailing_singletons ();
+
   return result;
 }
 
@@ -360,6 +363,9 @@
       idx_arg.elem (i) = idx_j;
     }
 
+  result.chop_trailing_singletons ();
+  idx_arg.chop_trailing_singletons ();
+
   return result;
 }
 
--- a/src/ChangeLog	Tue Mar 18 16:21:34 2008 -0400
+++ b/src/ChangeLog	Tue Mar 18 20:47:40 2008 -0400
@@ -1,3 +1,7 @@
+2008-03-18  David Bateman  <dbateman@free.fr>
+
+	* DLD-FUNCTIONS/minmax.cc: 64-bit indexing fix.
+
 2008-03-11  John W. Eaton  <jwe@octave.org>
 
 	* graphics.cc, graphics.h.in (class axes): New property, linewidth.
--- a/src/DLD-FUNCTIONS/minmax.cc	Tue Mar 18 16:21:34 2008 -0400
+++ b/src/DLD-FUNCTIONS/minmax.cc	Tue Mar 18 20:47:40 2008 -0400
@@ -106,7 +106,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); \
 	    } \
@@ -252,7 +252,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); \
 	    } \
@@ -440,6 +440,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\
@@ -487,6 +514,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	Tue Mar 18 16:21:34 2008 -0400
+++ b/test/test_arith.m	Tue Mar 18 20:47:40 2008 -0400
@@ -160,32 +160,6 @@
 %! s.a = 1;
 %! fail("lcm (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/pow2-1.m
 %!test
 %! x = [3, 0, -3];