diff src/pr-output.cc @ 4559:802818bfac91

[project @ 2003-10-28 19:13:43 by jwe]
author jwe
date Tue, 28 Oct 2003 19:13:43 +0000
parents 01ee68d18069
children 6cb22b9e3942
line wrap: on
line diff
--- a/src/pr-output.cc	Tue Oct 28 18:48:07 2003 +0000
+++ b/src/pr-output.cc	Tue Oct 28 19:13:43 2003 +0000
@@ -1273,12 +1273,30 @@
   else
     {
       os << "[]";
+
       if (Vprint_empty_dimensions)
 	os << "(" << nr << "x" << nc << ")";
     }
 }
 
 static void
+print_empty_nd_array (std::ostream& os, const dim_vector& dims,
+		      bool pr_as_read_syntax)
+{
+  assert (dims.any_zero ());
+
+  if (pr_as_read_syntax)
+    os << "zeros (" << dims.str (',') << ")";
+  else
+    {
+      os << "[]";
+
+      if (Vprint_empty_dimensions)
+	os << "(" << dims.str () << ")";
+    }
+}
+
+static void
 pr_scale_header (std::ostream& os, double scale)
 {
   if (Vfixed_point_format && ! print_g && scale != 1.0)
@@ -1488,63 +1506,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); \
+      if (nda.is_empty ()) \
+        print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); \
+      else \
+        { \
  \
-      int m = 1; \
+          int ndims = nda.ndims (); \
+ \
+          dim_vector dims = nda.dims (); \
  \
-      for (int i = 2; i < ndims; i++) \
-	m *= dims(i); \
+          Array<int> ra_idx (ndims, 0); \
  \
-      int nr = dims(0); \
-      int nc = dims(1); \
+          int m = 1; \
  \
-      for (int i = 0; i < m; i++) \
-	{ \
-	  std::string nm = "ans"; \
+          for (int i = 2; i < ndims; i++) \
+            m *= dims(i); \
+ \
+          int nr = dims(0); \
+          int nc = dims(1); \
  \
-	  if (m > 1) \
-	    { \
-	      nm += "(:,:,"; \
+          for (int i = 0; i < m; i++) \
+            { \
+              std::string nm = "ans"; \
  \
-	      OSSTREAM buf; \
+              if (m > 1) \
+                { \
+                  nm += "(:,:,"; \
  \
-	      for (int k = 2; k < ndims; k++) \
-		{ \
-		  buf << ra_idx(k) + 1; \
+                  OSSTREAM buf; \
  \
-		  if (k < ndims - 1) \
-		    buf << ","; \
-		  else \
-		    buf << ")"; \
-		} \
+                  for (int k = 2; k < ndims; k++) \
+                    { \
+                      buf << ra_idx(k) + 1; \
  \
-	      buf << OSSTREAM_ENDS; \
- \
-	      nm += OSSTREAM_STR (buf); \
+                      if (k < ndims - 1) \
+                        buf << ","; \
+                      else \
+                        buf << ")"; \
+                    } \
  \
-	      OSSTREAM_FREEZE (buf); \
-	    } \
+                  buf << OSSTREAM_ENDS; \
  \
-	  Array<idx_vector> idx (ndims); \
+                  nm += OSSTREAM_STR (buf); \
+ \
+                  OSSTREAM_FREEZE (buf); \
+                } \
  \
-	  idx(0) = idx_vector (':'); \
-	  idx(1) = idx_vector (':'); \
+              Array<idx_vector> idx (ndims); \
  \
-	  for (int k = 2; k < ndims; k++) \
-	    idx(k) = idx_vector (ra_idx(k) + 1); \
+              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)); \
+              octave_value page \
+                = MAT_T (Array2<ELT_T> (nda.index (idx), nr, nc)); \
+ \
+              page.print_with_name (os, nm); \
  \
-	  page.print_with_name (os, nm); \
- \
-	  if (i < m) \
-	    NDA_T::increment_index (ra_idx, dims, 2); \
-	} \
+              if (i < m) \
+                NDA_T::increment_index (ra_idx, dims, 2); \
+            } \
+        } \
     } \
   while (0)