changeset 10095:eb8ac0eed9f1

always chop dimension vector when constructing Arrays
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 13 Jan 2010 18:19:37 +0100
parents ab1101011a6d
children ffc5426c85a4
files liboctave/Array.cc liboctave/Array.h liboctave/ChangeLog liboctave/dim-vector.h
diffstat 4 files changed, 30 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/Array.cc	Wed Jan 13 06:00:14 2010 -0500
+++ b/liboctave/Array.cc	Wed Jan 13 18:19:37 2010 +0100
@@ -64,6 +64,7 @@
   // This goes here because if an exception is thrown by the above,
   // destructor will be never called.
   rep->count++;
+  dimensions.chop_trailing_singletons ();
 }
 
 template <class T>
@@ -107,6 +108,7 @@
   slice_len = rep->len;
 
   dimensions = dv;
+  dimensions.chop_trailing_singletons ();
 }
 
 template <class T>
@@ -493,8 +495,6 @@
       rh.permute (data (), retval.fortran_vec ());
     }
 
-  retval.chop_trailing_singletons ();
-
   return retval;
 }
 
@@ -834,6 +834,7 @@
       else if (all_colons)
         {
           // A(:,:,...,:) produces a shallow copy.
+          dv.chop_trailing_singletons ();
           retval = Array<T> (*this, dv);
         }
       else 
@@ -1329,8 +1330,7 @@
                 }
 
               resize_fill (rdv, rfv);
-              dv = dimensions;
-              chop_trailing_singletons ();
+              dv = rdv;
             }
 
           if (all_colons)
--- a/liboctave/Array.h	Wed Jan 13 06:00:14 2010 -0500
+++ b/liboctave/Array.h	Wed Jan 13 18:19:37 2010 +0100
@@ -145,6 +145,7 @@
     { 
       slice_data = rep->data;
       slice_len = rep->len;
+      dimensions.chop_trailing_singletons ();
     }
 
   // slice constructor
@@ -155,6 +156,7 @@
       rep->count++;
       slice_data = a.slice_data + l;
       slice_len = u - l;
+      dimensions.chop_trailing_singletons ();
     }
 
 private:
@@ -231,6 +233,7 @@
     { 
       slice_data = rep->data;
       slice_len = rep->len;
+      dimensions.chop_trailing_singletons ();
     }
 
   Array (const dim_vector& dv, const T& val)
@@ -240,6 +243,7 @@
       slice_data = rep->data;
       slice_len = rep->len;
       fill (val);
+      dimensions.chop_trailing_singletons ();
     }
 
   // Reshape constructor.
@@ -300,7 +304,7 @@
 
   Array<T> squeeze (void) const;
   
-  void chop_trailing_singletons (void) 
+  void chop_trailing_singletons (void) GCC_ATTR_DEPRECATED
   { dimensions.chop_trailing_singletons (); }
   
   octave_idx_type compute_index (const Array<octave_idx_type>& ra_idx) const;
--- a/liboctave/ChangeLog	Wed Jan 13 06:00:14 2010 -0500
+++ b/liboctave/ChangeLog	Wed Jan 13 18:19:37 2010 +0100
@@ -1,3 +1,19 @@
+2010-01-13  Jaroslav Hajek  <highegg@gmail.com>
+
+	* dim-vector.h (dim_vector::chop_trailing_singletons): Only uniquify
+	if really needed.
+	* Array.h (Array<T>::Array (T*, const dim_vector&)): Call
+	chop_trailing_singletons.
+	(Array<T>::Array (const Array<T>&, const dim_vector&,
+	octave_idx_type...)): Ditto.
+	(Array<T>::Array (const dim_vector&)): Ditto.
+	(Array<T>::Array (const dim_vector&, const T&)): Ditto.
+	(Array<T>::chop_trailing_singletons): Deprecate.
+	* Array.cc (Array::Array(const Array&, const dim_vector&)): Ditto.
+	(Array::index (const Array<idx_vector>&, ...)): Ditto.
+	(Array<T>::permute): Don't call deprecate method here.
+	(Array<T>::assign): Neither here.
+
 2010-01-11  Rik <octave@nomad.inbox5.com>
 
 	* Makefile.am: Remove unnecessary use of simple_move_if_change_rule to allow
--- a/liboctave/dim-vector.h	Wed Jan 13 06:00:14 2010 -0500
+++ b/liboctave/dim-vector.h	Wed Jan 13 18:19:37 2010 +0100
@@ -150,16 +150,15 @@
 
   void chop_trailing_singletons (void)
     {
-      make_unique ();
       int l = ndims();
-      for (int i = l - 1; i > 1; i--)
+      if (l > 2 && rep[l-1] == 1)
         {
-          if (rep[i] == 1)
+          make_unique ();
+          do
             l--;
-          else
-            break;
+          while (l > 2 && rep[l-1] == 1);
+          ndims() = l;
         }
-      ndims() = l;
     }
 
   void chop_all_singletons (void)