changeset 4532:01ee68d18069

[project @ 2003-10-10 00:49:54 by jwe]
author jwe
date Fri, 10 Oct 2003 00:49:55 +0000
parents b570d7825fb9
children ed2990fab58f
files ChangeLog liboctave/Array.cc liboctave/Array.h liboctave/ArrayN.h liboctave/CNDArray.cc liboctave/CNDArray.h liboctave/ChangeLog liboctave/boolNDArray.cc liboctave/boolNDArray.h liboctave/chNDArray.cc liboctave/chNDArray.h liboctave/dNDArray.cc liboctave/dNDArray.h liboctave/dim-vector.h src/ChangeLog src/OPERATORS/op-m-m.cc src/data.cc src/ov-base-mat.h src/ov-base.cc src/ov-base.h src/ov.cc src/ov.h src/pr-output.cc
diffstat 23 files changed, 312 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Oct 07 14:57:39 2003 +0000
+++ b/ChangeLog	Fri Oct 10 00:49:55 2003 +0000
@@ -1,3 +1,7 @@
+2003-10-07  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* configure.in (AC_PREREQ): Require 2.57.
+
 2003-09-19  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* configure.in (AH_BOTTOM): Don't define HEAVYWEIGHT_INDEXING here.
--- a/liboctave/Array.cc	Tue Oct 07 14:57:39 2003 +0000
+++ b/liboctave/Array.cc	Fri Oct 10 00:49:55 2003 +0000
@@ -52,6 +52,43 @@
   delete [] idx;
 }
 
+template <class T>
+Array<T>
+Array<T>::squeeze (void) const
+{
+  Array<T> retval = *this;
+
+  bool dims_changed = false;
+
+  dim_vector new_dimensions = dimensions;
+
+  int k = 0;
+
+  for (int i = 0; i < ndims (); i++)
+    {
+      if (dimensions(i) == 1)
+	dims_changed = true;
+      else
+	new_dimensions(k++) = dimensions(i);
+    }
+
+  if (dims_changed)
+    {
+      if (k == 0)
+	new_dimensions = dim_vector (1);
+      else
+	new_dimensions.resize (k);
+
+      Array<T> retval = *this;
+
+      retval.make_unique ();
+
+      retval.dimensions = new_dimensions;
+    }
+
+  return retval;
+}
+
 // A guess (should be quite conservative).
 #define MALLOC_OVERHEAD 1024
 
@@ -85,13 +122,10 @@
   int nt = nr + nc;
   double dt = dr * dc;
 
-  if (dt <= 0.5)
+  if (dt < 0.5)
     {
       nt--;
       dt *= 2;
-
-      if (dt <= 0.5)
-	nt--;
     }
 
   return (nt < nl || (nt == nl && dt < dl)) ? r * c : max_items;
@@ -128,13 +162,16 @@
   int nt = nr + nc + np;
   double dt = dr * dc * dp;
 
-  if (dt <= 0.5)
+  if (dt < 0.5)
     {
       nt--;
       dt *= 2;
 
-      if (dt <= 0.5)
-	nt--;
+      if (dt < 0.5)
+	{
+	  nt--;
+	  dt *= 2;
+	}
     }
 
   return (nt < nl || (nt == nl && dt < dl)) ? r * c * p : max_items;
@@ -178,15 +215,12 @@
 
       nt += nra_idx;
       dt *= dra_idx;
-    }
-
-  if (dt <= 0.5)
-    {
-      nt--;
-      dt *= 2;
-
-      if (dt <= 0.5)
-	nt--;
+
+      if (dt < 0.5)
+	{
+	  nt--;
+	  dt *= 2;
+	}
     }
 
   if (nt < nl || (nt == nl && dt < dl))
--- a/liboctave/Array.h	Tue Oct 07 14:57:39 2003 +0000
+++ b/liboctave/Array.h	Fri Oct 10 00:49:55 2003 +0000
@@ -246,6 +246,8 @@
 
   dim_vector dims (void) const { return dimensions; }
 
+  Array<T> squeeze (void) const;
+
   static int get_size (int r, int c);
   static int get_size (int r, int c, int p);
   static int get_size (const dim_vector& dims);
--- a/liboctave/ArrayN.h	Tue Oct 07 14:57:39 2003 +0000
+++ b/liboctave/ArrayN.h	Fri Oct 10 00:49:55 2003 +0000
@@ -71,6 +71,8 @@
 
   ArrayN (const ArrayN<T>& a) : Array<T> (a, a.dims ()) { }
 
+  ArrayN (const Array<T>& a) : Array<T> (a) { }
+
   ArrayN (const Array<T>& a, const dim_vector& dims) : Array<T> (a, dims) { }
 
   ~ArrayN (void) { }
@@ -89,6 +91,8 @@
   void resize (const dim_vector& dims, const T& val)
     { Array<T>::resize (dims, val); }
 
+  ArrayN<T> squeeze (void) const { return Array<T>::squeeze (); }
+
   ArrayN<T>& insert (const ArrayN<T>& a, const dim_vector& dims)
     {
       Array<T>::insert (a, dims);
--- a/liboctave/CNDArray.cc	Tue Oct 07 14:57:39 2003 +0000
+++ b/liboctave/CNDArray.cc	Fri Oct 10 00:49:55 2003 +0000
@@ -33,6 +33,8 @@
 #include "mx-base.h"
 #include "lo-ieee.h"
 
+#include "ArrayN-inline.h"
+
 // XXX FIXME XXX -- this is not quite the right thing.
 
 boolMatrix
@@ -96,6 +98,14 @@
   return retval;
 }
 
+void
+ComplexNDArray::increment_index (Array<int>& ra_idx,
+				 const dim_vector& dimensions,
+				 int start_dimension)
+{
+  ::increment_index (ra_idx, dimensions, start_dimension);
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/liboctave/CNDArray.h	Tue Oct 07 14:57:39 2003 +0000
+++ b/liboctave/CNDArray.h	Fri Oct 10 00:49:55 2003 +0000
@@ -69,6 +69,12 @@
 
   ComplexMatrix matrix_value (void) const;
 
+  ComplexNDArray squeeze (void) const { return ArrayN<Complex>::squeeze (); }
+
+  static void increment_index (Array<int>& ra_idx,
+			       const dim_vector& dimensions,
+			       int start_dimension = 0);
+
   // i/o
 
   // friend std::ostream& operator << (std::ostream& os, const NDArray& a);
--- a/liboctave/ChangeLog	Tue Oct 07 14:57:39 2003 +0000
+++ b/liboctave/ChangeLog	Fri Oct 10 00:49:55 2003 +0000
@@ -1,3 +1,22 @@
+2003-10-09  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* CNDArray.cc (ComplexNDArray::increment_index): New function.
+	* dNDArray.cc (NDArray::increment_index): Likewise.
+	* boolNDArray.cc (boolNDArray::increment_index): Likewise.
+	* chNDArray.cc (charNDArray::increment_index): Likewise.
+
+	* dim-vector.h (rows, cols): Delete unused data members.
+
+	* Array.cc (Array<T>::get_size): Fix thinko.
+
+2003-10-08  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* Array.cc (Array<T>::squeeze): New function.
+	* CNDArray.h (ComplexNDArray::squeeze): Likewise.
+	* dNDArray.h (NDArray::squeeze): Likewise.
+	* boolNDArray.h (boolNDArray::squeeze): Likewise.
+	* chNDArray.h (charNDArray::squeeze): Likewise.
+
 2003-10-06  Petter Risholm  <risholm@stud.ntnu.no>
 
 	* Array.cc (ArrayN<T>::indexN): New definition.
--- a/liboctave/boolNDArray.cc	Tue Oct 07 14:57:39 2003 +0000
+++ b/liboctave/boolNDArray.cc	Fri Oct 10 00:49:55 2003 +0000
@@ -33,6 +33,8 @@
 #include "mx-base.h"
 #include "lo-ieee.h"
 
+#include "ArrayN-inline.h"
+
 // XXX FIXME XXX -- this is not quite the right thing.
 
 boolMatrix
@@ -96,6 +98,14 @@
   return retval;
 }
 
+void
+boolNDArray::increment_index (Array<int>& ra_idx,
+			      const dim_vector& dimensions,
+			      int start_dimension)
+{
+  ::increment_index (ra_idx, dimensions, start_dimension);
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/liboctave/boolNDArray.h	Tue Oct 07 14:57:39 2003 +0000
+++ b/liboctave/boolNDArray.h	Fri Oct 10 00:49:55 2003 +0000
@@ -69,6 +69,12 @@
 
   boolMatrix matrix_value (void) const;
 
+  boolNDArray squeeze (void) const { return ArrayN<bool>::squeeze (); }
+
+  static void increment_index (Array<int>& ra_idx,
+			       const dim_vector& dimensions,
+			       int start_dimension = 0);
+
   // i/o
 
   // friend std::ostream& operator << (std::ostream& os, const NDArray& a);
--- a/liboctave/chNDArray.cc	Tue Oct 07 14:57:39 2003 +0000
+++ b/liboctave/chNDArray.cc	Fri Oct 10 00:49:55 2003 +0000
@@ -33,6 +33,8 @@
 #include "mx-base.h"
 #include "lo-ieee.h"
 
+#include "ArrayN-inline.h"
+
 // XXX FIXME XXX -- this is not quite the right thing.
 
 boolMatrix
@@ -96,6 +98,14 @@
   return retval;
 }
 
+void
+charNDArray::increment_index (Array<int>& ra_idx,
+			      const dim_vector& dimensions,
+			      int start_dimension)
+{
+  ::increment_index (ra_idx, dimensions, start_dimension);
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/liboctave/chNDArray.h	Tue Oct 07 14:57:39 2003 +0000
+++ b/liboctave/chNDArray.h	Fri Oct 10 00:49:55 2003 +0000
@@ -74,6 +74,12 @@
 
   charMatrix matrix_value (void) const;
 
+  charNDArray squeeze (void) const { return ArrayN<char>::squeeze (); }
+
+  static void increment_index (Array<int>& ra_idx,
+			       const dim_vector& dimensions,
+			       int start_dimension = 0);
+
   // i/o
 
   // friend std::ostream& operator << (std::ostream& os, const charNDArray& a);
--- a/liboctave/dNDArray.cc	Tue Oct 07 14:57:39 2003 +0000
+++ b/liboctave/dNDArray.cc	Fri Oct 10 00:49:55 2003 +0000
@@ -34,6 +34,8 @@
 #include "lo-error.h"
 #include "lo-ieee.h"
 
+#include "ArrayN-inline.h"
+
 // XXX FIXME XXX -- this is not quite the right thing.
 
 boolMatrix
@@ -70,6 +72,40 @@
   return retval;
 }
 
+Matrix
+NDArray::matrix_value (void) const
+{
+  Matrix retval;
+
+  int nd = ndims ();
+
+  switch (nd)
+    {
+    case 1:
+      retval = Matrix (Array2<double> (*this, dimensions(0), 1));
+      break;
+
+    case 2:
+      retval = Matrix (Array2<double> (*this, dimensions(0), dimensions(1)));
+      break;
+
+    default:
+      (*current_liboctave_error_handler)
+	("invalid converstion of NDArray to Matrix");
+      break;
+    }
+
+  return retval;
+}
+
+void
+NDArray::increment_index (Array<int>& ra_idx,
+			  const dim_vector& dimensions,
+			  int start_dimension)
+{
+  ::increment_index (ra_idx, dimensions, start_dimension);
+}
+
 bool
 NDArray::any_element_is_negative (bool neg_zero) const
 {
@@ -120,32 +156,6 @@
   return true;
 }
 
-Matrix
-NDArray::matrix_value (void) const
-{
-  Matrix retval;
-
-  int nd = ndims ();
-
-  switch (nd)
-    {
-    case 1:
-      retval = Matrix (Array2<double> (*this, dimensions(0), 1));
-      break;
-
-    case 2:
-      retval = Matrix (Array2<double> (*this, dimensions(0), dimensions(1)));
-      break;
-
-    default:
-      (*current_liboctave_error_handler)
-	("invalid converstion of NDArray to Matrix");
-      break;
-    }
-
-  return retval;
-}
-
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/liboctave/dNDArray.h	Tue Oct 07 14:57:39 2003 +0000
+++ b/liboctave/dNDArray.h	Fri Oct 10 00:49:55 2003 +0000
@@ -68,6 +68,12 @@
 
   Matrix matrix_value (void) const;
 
+  NDArray squeeze (void) const { return ArrayN<double>::squeeze (); }
+
+  static void increment_index (Array<int>& ra_idx,
+			       const dim_vector& dimensions,
+			       int start_dimension = 0);
+
   // i/o
 
   // friend std::ostream& operator << (std::ostream& os, const NDArray& a);
--- a/liboctave/dim-vector.h	Tue Oct 07 14:57:39 2003 +0000
+++ b/liboctave/dim-vector.h	Fri Oct 10 00:49:55 2003 +0000
@@ -118,8 +118,6 @@
 
 private:
 
-  int rows;
-  int cols;
   int ndims;
   int *dims;
 };
--- a/src/ChangeLog	Tue Oct 07 14:57:39 2003 +0000
+++ b/src/ChangeLog	Fri Oct 10 00:49:55 2003 +0000
@@ -1,3 +1,19 @@
+2003-10-09  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* pr-output.cc (PRINT_ND_ARRAY): New macro.
+	(octave_print_internal): Use it.
+
+2003-10-08  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* ov.cc	(octave_value::octave_value (const ArrayN<octave_value>&,
+	bool)):	New constructor.
+	* ov.h: Provide decl.
+
+	* ov.h (octave_value::squeeze): New virtual function.
+	* ov-base.cc (squeeze): Provide default implementation.
+	* ov-base-mat.h (octave_base_matrix::squeeze): New function.
+	* data.cc (Fsqueeze): New function.
+
 2003-10-03  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* load-save.cc (make_valid_identifier): Return new string.
--- a/src/OPERATORS/op-m-m.cc	Tue Oct 07 14:57:39 2003 +0000
+++ b/src/OPERATORS/op-m-m.cc	Fri Oct 10 00:49:55 2003 +0000
@@ -88,6 +88,20 @@
 DEFBINOP_FN (el_and, matrix, matrix, mx_el_and)
 DEFBINOP_FN (el_or, matrix, matrix, mx_el_or)
 
+#if 0
+static octave_value
+oct_assignop_assign (octave_value& a1,
+		     const octave_value_list& idx,
+		     const octave_value& a2)
+{
+  CAST_BINOP_ARGS (octave_matrix&, const octave_matrix&);
+
+  v1.assign (idx, v2.double_nd_array_value ());
+
+  return octave_value ();
+}
+#endif
+
 DEFASSIGNOP_FN (assign, matrix, matrix, assign)
 
 void
--- a/src/data.cc	Tue Oct 07 14:57:39 2003 +0000
+++ b/src/data.cc	Fri Oct 10 00:49:55 2003 +0000
@@ -1184,6 +1184,22 @@
   return retval;
 }
 
+DEFUN (squeeze, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} squeeze (@var{x})\n\
+Remove singleton dimensions from @var{x} and return the result.\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  if (args.length () == 1)
+    return args(0).squeeze ();
+  else
+    print_usage ("squeeze");    
+
+  return retval;
+}
+
 void
 symbols_of_data (void)
 {
--- a/src/ov-base-mat.h	Tue Oct 07 14:57:39 2003 +0000
+++ b/src/ov-base-mat.h	Fri Oct 10 00:49:55 2003 +0000
@@ -66,6 +66,8 @@
   octave_value *clone (void) const { return new octave_base_matrix (*this); }
   octave_value *empty_clone (void) const { return new octave_base_matrix (); }
 
+  octave_value squeeze (void) const { return matrix.squeeze (); }
+
   octave_value subsref (const std::string& type,
 			const std::list<octave_value_list>& idx);
 
--- a/src/ov-base.cc	Tue Oct 07 14:57:39 2003 +0000
+++ b/src/ov-base.cc	Fri Oct 10 00:49:55 2003 +0000
@@ -56,6 +56,14 @@
 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_base_value, "<unknown type>");
 
 octave_value
+octave_base_value::squeeze (void) const
+{
+  std::string nm = type_name ();
+  error ("squeeze: invalid operation for %s type", nm.c_str ());
+  return octave_value ();
+}
+
+octave_value
 octave_base_value::subsref (const std::string&,
 			    const std::list<octave_value_list>&)
 {
--- a/src/ov-base.h	Tue Oct 07 14:57:39 2003 +0000
+++ b/src/ov-base.h	Fri Oct 10 00:49:55 2003 +0000
@@ -68,6 +68,8 @@
   type_conv_fcn numeric_conversion_function (void) const
     { return static_cast<type_conv_fcn> (0); }
 
+  octave_value squeeze (void) const;
+
   octave_value *try_narrowing_conversion (void)
     { return static_cast<octave_value *> (0); }
 
--- a/src/ov.cc	Tue Oct 07 14:57:39 2003 +0000
+++ b/src/ov.cc	Fri Oct 10 00:49:55 2003 +0000
@@ -410,6 +410,19 @@
   rep->count = 1;
 }
 
+octave_value::octave_value (const ArrayN<octave_value>& a, bool is_cs_list)
+  : rep (0)
+{
+  Cell c (a);
+
+  if (is_cs_list)
+    rep = new octave_cs_list (c);
+  else
+    rep = new octave_cell (c);
+
+  rep->count = 1;
+}
+
 octave_value::octave_value (const Matrix& m)
   : rep (new octave_matrix (m))
 {
--- a/src/ov.h	Tue Oct 07 14:57:39 2003 +0000
+++ b/src/ov.h	Fri Oct 10 00:49:55 2003 +0000
@@ -182,7 +182,8 @@
 
   octave_value (octave_time t);
   octave_value (double d);
-  octave_value (const Cell& m, bool is_cs_list = false);
+  octave_value (const ArrayN<octave_value>& a, bool is_cs_list = false);
+  octave_value (const Cell& c, bool is_cs_list = false);
   octave_value (const Matrix& m);
   octave_value (const NDArray& nda);
   octave_value (const DiagMatrix& d);
@@ -269,6 +270,9 @@
 
   void maybe_mutate (void);
 
+  virtual octave_value squeeze (void) const
+    { return rep->squeeze (); }
+
   virtual octave_value *try_narrowing_conversion (void)
     { return rep->try_narrowing_conversion (); }
 
--- a/src/pr-output.cc	Tue Oct 07 14:57:39 2003 +0000
+++ b/src/pr-output.cc	Fri Oct 10 00:49:55 2003 +0000
@@ -1485,6 +1485,69 @@
     }
 }
 
+#define PRINT_ND_ARRAY(os, nda, NDA_T, ELT_T, MAT_T) \
+  do \
+    { \
+      int ndims = nda.ndims (); \
+ \
+      dim_vector dims = nda.dims (); \
+ \
+      Array<int> ra_idx (ndims, 0); \
+ \
+      int m = 1; \
+ \
+      for (int i = 2; i < ndims; i++) \
+	m *= dims(i); \
+ \
+      int nr = dims(0); \
+      int nc = dims(1); \
+ \
+      for (int i = 0; i < m; i++) \
+	{ \
+	  std::string nm = "ans"; \
+ \
+	  if (m > 1) \
+	    { \
+	      nm += "(:,:,"; \
+ \
+	      OSSTREAM buf; \
+ \
+	      for (int k = 2; k < ndims; k++) \
+		{ \
+		  buf << ra_idx(k) + 1; \
+ \
+		  if (k < ndims - 1) \
+		    buf << ","; \
+		  else \
+		    buf << ")"; \
+		} \
+ \
+	      buf << OSSTREAM_ENDS; \
+ \
+	      nm += OSSTREAM_STR (buf); \
+ \
+	      OSSTREAM_FREEZE (buf); \
+	    } \
+ \
+	  Array<idx_vector> idx (ndims); \
+ \
+	  idx(0) = idx_vector (':'); \
+	  idx(1) = idx_vector (':'); \
+ \
+	  for (int k = 2; k < ndims; k++) \
+	    idx(k) = idx_vector (ra_idx(k) + 1); \
+ \
+          octave_value page \
+            = MAT_T (Array2<ELT_T> (nda.index (idx), nr, nc)); \
+ \
+	  page.print_with_name (os, nm); \
+ \
+	  if (i < m) \
+	    NDA_T::increment_index (ra_idx, dims, 2); \
+	} \
+    } \
+  while (0)
+
 void
 octave_print_internal (std::ostream& os, const NDArray& nda,
 		       bool pr_as_read_syntax, int extra_indent)
@@ -1498,7 +1561,7 @@
       break;
 
     default:
-      os << nda;
+      PRINT_ND_ARRAY (os, nda, NDArray, double, Matrix);
       break;
     }
 }
@@ -1691,7 +1754,7 @@
       break;
 
     default:
-      os << nda;
+      PRINT_ND_ARRAY (os, nda, ComplexNDArray, Complex, ComplexMatrix);
       break;
     }
 }
@@ -1826,7 +1889,7 @@
       break;
 
     default:
-      os << nda;
+      PRINT_ND_ARRAY (os, nda, boolNDArray, bool, boolMatrix);
       break;
     }
 }
@@ -1892,7 +1955,7 @@
       break;
 
     default:
-      os << nda;
+      PRINT_ND_ARRAY (os, nda, charNDArray, char, charMatrix);
       break;
     }
 }