diff liboctave/Array.cc @ 9732:b4fdfee405b5

remove ArrayN<T> + fix nonhom. diag-scalar ops
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 16 Oct 2009 13:12:31 +0200
parents 7b9cbaad68d6
children 01f897d8a130
line wrap: on
line diff
--- a/liboctave/Array.cc	Fri Oct 16 10:28:26 2009 +0200
+++ b/liboctave/Array.cc	Fri Oct 16 13:12:31 2009 +0200
@@ -2937,6 +2937,109 @@
   template <> void Array<T>::instantiation_guard () { } \
   template class API Array<T>
 
+// FIXME: is this used?
+
+template <class T>
+std::ostream&
+operator << (std::ostream& os, const Array<T>& a)
+{
+  dim_vector a_dims = a.dims ();
+
+  int n_dims = a_dims.length ();
+
+  os << n_dims << "-dimensional array";
+
+  if (n_dims)
+    os << " (" << a_dims.str () << ")";
+
+  os <<"\n\n";
+
+  if (n_dims)
+    {
+      os << "data:";
+
+      Array<octave_idx_type> ra_idx (n_dims, 0);
+
+      // Number of times the first 2d-array is to be displayed.
+
+      octave_idx_type m = 1;
+      for (int i = 2; i < n_dims; i++)
+	m *= a_dims(i);
+
+      if (m == 1)
+        {
+          octave_idx_type rows = 0;
+          octave_idx_type cols = 0;
+
+          switch (n_dims)
+            {
+	    case 2:
+	      rows = a_dims(0);
+	      cols = a_dims(1);
+
+	      for (octave_idx_type j = 0; j < rows; j++)
+		{
+		  ra_idx(0) = j;
+		  for (octave_idx_type k = 0; k < cols; k++)
+		    {
+		      ra_idx(1) = k;
+		      os << " " << a.elem(ra_idx);
+		    }
+		  os << "\n";
+		}
+	      break;
+
+	    default:
+	      rows = a_dims(0);
+
+	      for (octave_idx_type k = 0; k < rows; k++)
+		{
+		  ra_idx(0) = k;
+		  os << " " << a.elem(ra_idx);
+		}
+	      break;
+	    }
+
+          os << "\n";
+        }
+      else
+        {
+          octave_idx_type rows = a_dims(0);
+          octave_idx_type cols = a_dims(1);
+
+          for (int i = 0; i < m; i++)
+            {
+              os << "\n(:,:,";
+
+              for (int j = 2; j < n_dims - 1; j++)
+		os << ra_idx(j) + 1 << ",";
+
+	      os << ra_idx(n_dims - 1) + 1 << ") = \n";
+
+	      for (octave_idx_type j = 0; j < rows; j++)
+	        {
+	          ra_idx(0) = j;
+
+	          for (octave_idx_type k = 0; k < cols; k++)
+	            {
+		      ra_idx(1) = k;
+		      os << " " << a.elem(ra_idx);
+		    }
+
+	          os << "\n";
+	        }
+
+	      os << "\n";
+
+	      if (i != m - 1)
+		increment_index (ra_idx, a_dims, 2);
+            }
+        }
+    }
+
+  return os;
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***