changeset 11859:5d7aa47a5797 release-3-0-x

fix null assignment behaviour
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 29 Sep 2008 07:32:19 +0200
parents 42c40c6ebb8e
children 0f3d1dd22905
files liboctave/Array.cc liboctave/ChangeLog
diffstat 2 files changed, 27 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/Array.cc	Mon Sep 29 07:24:07 2008 +0200
+++ b/liboctave/Array.cc	Mon Sep 29 07:32:19 2008 +0200
@@ -1612,7 +1612,7 @@
             }
 	}
     }
-  else
+  else if (! (idx_i.orig_empty () || idx_j.orig_empty ()))
     {
       (*current_liboctave_error_handler)
         ("a null assignment can have only one non-colon index");
@@ -1632,6 +1632,21 @@
 {
   octave_idx_type n_idx = ra_idx.length ();
 
+  // Special case matrices
+  if (ndims () == 2)
+    {
+      if (n_idx == 1)
+        {
+          maybe_delete_elements (ra_idx (0));
+          return;
+        }
+      else if (n_idx == 2)
+        {
+          maybe_delete_elements (ra_idx (0), ra_idx (1));
+          return;
+        }
+    }
+
   dim_vector lhs_dims = dims ();
 
   int n_lhs_dims = lhs_dims.length ();
@@ -1672,6 +1687,7 @@
 
   for (octave_idx_type i = 0; i < n_idx; i++)
     {
+      if (ra_idx(i).orig_empty ()) return;
       idx_is_colon_equiv(i) = ra_idx(i).is_colon_equiv (lhs_dims(i), 1);
 
       idx_is_colon(i) = ra_idx(i).is_colon ();
@@ -1727,18 +1743,15 @@
   if (idx_ok)
     {
       if (n_idx > 1
-	  && (all_ones (idx_is_colon) || all_ones (idx_is_colon_equiv)))
+	  && (all_ones (idx_is_colon)))
 	{
 	  // A(:,:,:) -- we are deleting elements in all dimensions, so
 	  // the result is [](0x0x0).
 
-	  dim_vector zeros;
-	  zeros.resize (n_idx);
-
-	  for (int i = 0; i < n_idx; i++)
-	    zeros(i) = 0;
-
-	  resize (zeros, rfv);
+	  dim_vector newdim = dims ();
+          newdim(0) = 0;
+
+	  resize (newdim, rfv);
 	}
 
       else if (n_idx > 1
--- a/liboctave/ChangeLog	Mon Sep 29 07:24:07 2008 +0200
+++ b/liboctave/ChangeLog	Mon Sep 29 07:32:19 2008 +0200
@@ -1,3 +1,8 @@
+2008-09-29  Jaroslav Hajek  <highegg@gmail.com>
+
+	* Array.cc (Array<T>::maybe_delete_elements_2, Array<T>::maybe_delete_elements): 
+	Ignore null assignments with empty index vectors.
+
 2008-09-19  John W. Eaton  <jwe@octave.org>
 
 	* Array.cc (assign1, assign2, assignN):