changeset 8999:dc07bc4157b8

allow empty matrices in stream input operators
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 20 Mar 2009 11:39:25 +0100
parents a48fba01e4ac
children cc916241e811
files liboctave/CColVector.cc liboctave/CMatrix.cc liboctave/CNDArray.cc liboctave/CRowVector.cc liboctave/CSparse.cc liboctave/ChangeLog liboctave/boolSparse.cc liboctave/dColVector.cc liboctave/dMatrix.cc liboctave/dNDArray.cc liboctave/dRowVector.cc liboctave/dSparse.cc liboctave/fCColVector.cc liboctave/fCMatrix.cc liboctave/fCNDArray.cc liboctave/fCRowVector.cc liboctave/fColVector.cc liboctave/fMatrix.cc liboctave/fNDArray.cc liboctave/fRowVector.cc liboctave/intNDArray.cc src/ChangeLog src/ov-cx-mat.cc src/ov-flt-cx-mat.cc src/ov-flt-re-mat.cc src/ov-re-mat.cc
diffstat 26 files changed, 68 insertions(+), 112 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/CColVector.cc
+++ b/liboctave/CColVector.cc
@@ -524,9 +524,7 @@
 {
   octave_idx_type len = a.length();
 
-  if (len < 1)
-    is.clear (std::ios::badbit);
-  else
+  if (len > 0)
     {
       double tmp;
       for (octave_idx_type i = 0; i < len; i++)
--- a/liboctave/CMatrix.cc
+++ b/liboctave/CMatrix.cc
@@ -3640,9 +3640,7 @@
   octave_idx_type nr = a.rows ();
   octave_idx_type nc = a.cols ();
 
-  if (nr < 1 || nc < 1)
-    is.clear (std::ios::badbit);
-  else
+  if (nr > 0 && nc > 0)
     {
       Complex tmp;
       for (octave_idx_type i = 0; i < nr; i++)
--- a/liboctave/CNDArray.cc
+++ b/liboctave/CNDArray.cc
@@ -916,9 +916,7 @@
 {
   octave_idx_type nel = a.nelem ();
 
-  if (nel < 1 )
-    is.clear (std::ios::badbit);
-  else
+  if (nel > 0)
     {
       Complex tmp;
       for (octave_idx_type i = 0; i < nel; i++)
--- a/liboctave/CRowVector.cc
+++ b/liboctave/CRowVector.cc
@@ -434,9 +434,7 @@
 {
   octave_idx_type len = a.length();
 
-  if (len < 1)
-    is.clear (std::ios::badbit);
-  else
+  if (len > 0)
     {
       Complex tmp;
       for (octave_idx_type i = 0; i < len; i++)
--- a/liboctave/CSparse.cc
+++ b/liboctave/CSparse.cc
@@ -7470,9 +7470,7 @@
   octave_idx_type nc = a.cols ();
   octave_idx_type nz = a.nzmax ();
 
-  if (nr < 1 || nc < 1)
-    is.clear (std::ios::badbit);
-  else
+  if (nr > 0 && nc > 0)
     {
       octave_idx_type itmp, jtmp, jold = 0;
       Complex tmp;
--- a/liboctave/ChangeLog
+++ b/liboctave/ChangeLog
@@ -1,3 +1,12 @@
+2009-03-20  Jaroslav Hajek  <highegg@gmail.com>
+
+	
+	* CColVector.cc, CMatrix.cc, CNDArray.cc, CRowVector.cc, CSparse.cc,
+	boolSparse.cc, dColVector.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc,
+	dSparse.cc, fCColVector.cc, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc,
+	fColVector.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc, intNDArray.cc:
+	Allow empty arrays in stream input operators.
+
 2009-03-20  Jaroslav Hajek  <highegg@gmail.com>
 
 	* Array.h (Array<T>::fastmap): New method.
--- a/liboctave/boolSparse.cc
+++ b/liboctave/boolSparse.cc
@@ -184,9 +184,7 @@
   octave_idx_type nc = a.cols ();
   octave_idx_type nz = a.nzmax ();
 
-  if (nr < 1 || nc < 1)
-    is.clear (std::ios::badbit);
-  else
+  if (nr > 0 && nc > 0)
     {
       octave_idx_type itmp, jtmp, jold = 0;
       bool tmp;
--- a/liboctave/dColVector.cc
+++ b/liboctave/dColVector.cc
@@ -321,9 +321,7 @@
 {
   octave_idx_type len = a.length();
 
-  if (len < 1)
-    is.clear (std::ios::badbit);
-  else
+  if (len > 0)
     {
       double tmp;
       for (octave_idx_type i = 0; i < len; i++)
--- a/liboctave/dMatrix.cc
+++ b/liboctave/dMatrix.cc
@@ -3058,9 +3058,7 @@
   octave_idx_type nr = a.rows ();
   octave_idx_type nc = a.cols ();
 
-  if (nr < 1 || nc < 1)
-    is.clear (std::ios::badbit);
-  else
+  if (nr > 0 && nc > 0)
     {
       double tmp;
       for (octave_idx_type i = 0; i < nr; i++)
--- a/liboctave/dNDArray.cc
+++ b/liboctave/dNDArray.cc
@@ -965,9 +965,7 @@
 {
   octave_idx_type nel = a.nelem ();
 
-  if (nel < 1 )
-    is.clear (std::ios::badbit);
-  else
+  if (nel > 0)
     {
       double tmp;
       for (octave_idx_type i = 0; i < nel; i++)
--- a/liboctave/dRowVector.cc
+++ b/liboctave/dRowVector.cc
@@ -291,9 +291,7 @@
 {
   octave_idx_type len = a.length();
 
-  if (len < 1)
-    is.clear (std::ios::badbit);
-  else
+  if (len > 0)
     {
       double tmp;
       for (octave_idx_type i = 0; i < len; i++)
--- a/liboctave/dSparse.cc
+++ b/liboctave/dSparse.cc
@@ -7588,9 +7588,7 @@
   octave_idx_type nc = a.cols ();
   octave_idx_type nz = a.nzmax ();
 
-  if (nr < 1 || nc < 1)
-    is.clear (std::ios::badbit);
-  else
+  if (nr > 0 && nc > 0)
     {
       octave_idx_type itmp, jtmp, jold = 0;
       double tmp;
--- a/liboctave/fCColVector.cc
+++ b/liboctave/fCColVector.cc
@@ -524,9 +524,7 @@
 {
   octave_idx_type len = a.length();
 
-  if (len < 1)
-    is.clear (std::ios::badbit);
-  else
+  if (len > 0)
     {
       float tmp;
       for (octave_idx_type i = 0; i < len; i++)
--- a/liboctave/fCMatrix.cc
+++ b/liboctave/fCMatrix.cc
@@ -3633,9 +3633,7 @@
   octave_idx_type nr = a.rows ();
   octave_idx_type nc = a.cols ();
 
-  if (nr < 1 || nc < 1)
-    is.clear (std::ios::badbit);
-  else
+  if (nr > 0 && nc > 0)
     {
       FloatComplex tmp;
       for (octave_idx_type i = 0; i < nr; i++)
--- a/liboctave/fCNDArray.cc
+++ b/liboctave/fCNDArray.cc
@@ -911,9 +911,7 @@
 {
   octave_idx_type nel = a.nelem ();
 
-  if (nel < 1 )
-    is.clear (std::ios::badbit);
-  else
+  if (nel > 0)
     {
       FloatComplex tmp;
       for (octave_idx_type i = 0; i < nel; i++)
--- a/liboctave/fCRowVector.cc
+++ b/liboctave/fCRowVector.cc
@@ -434,9 +434,7 @@
 {
   octave_idx_type len = a.length();
 
-  if (len < 1)
-    is.clear (std::ios::badbit);
-  else
+  if (len > 0)
     {
       FloatComplex tmp;
       for (octave_idx_type i = 0; i < len; i++)
--- a/liboctave/fColVector.cc
+++ b/liboctave/fColVector.cc
@@ -321,9 +321,7 @@
 {
   octave_idx_type len = a.length();
 
-  if (len < 1)
-    is.clear (std::ios::badbit);
-  else
+  if (len > 0)
     {
       float tmp;
       for (octave_idx_type i = 0; i < len; i++)
--- a/liboctave/fMatrix.cc
+++ b/liboctave/fMatrix.cc
@@ -3057,9 +3057,7 @@
   octave_idx_type nr = a.rows ();
   octave_idx_type nc = a.cols ();
 
-  if (nr < 1 || nc < 1)
-    is.clear (std::ios::badbit);
-  else
+  if (nr > 0 && nc > 0)
     {
       float tmp;
       for (octave_idx_type i = 0; i < nr; i++)
--- a/liboctave/fNDArray.cc
+++ b/liboctave/fNDArray.cc
@@ -920,9 +920,7 @@
 {
   octave_idx_type nel = a.nelem ();
 
-  if (nel < 1 )
-    is.clear (std::ios::badbit);
-  else
+  if (nel > 0)
     {
       float tmp;
       for (octave_idx_type i = 0; i < nel; i++)
--- a/liboctave/fRowVector.cc
+++ b/liboctave/fRowVector.cc
@@ -291,9 +291,7 @@
 {
   octave_idx_type len = a.length();
 
-  if (len < 1)
-    is.clear (std::ios::badbit);
-  else
+  if (len > 0)
     {
       float tmp;
       for (octave_idx_type i = 0; i < len; i++)
--- a/liboctave/intNDArray.cc
+++ b/liboctave/intNDArray.cc
@@ -146,9 +146,7 @@
 {
   octave_idx_type nel = a.nelem ();
 
-  if (nel < 1 )
-    is.clear (std::ios::badbit);
-  else
+  if (nel > 0)
     {
       T tmp;
 
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2009-03-20  Jaroslav Hajek  <highegg@gmail.com>
+
+	* ov-re-mat.cc (octave_matrix::load_ascii): Simplify.
+	* ov-flt-re-mat.cc (octave_float_matrix::load_ascii): Simplify.
+	* ov-cx-mat.cc (octave_complex_matrix::load_ascii): Simplify.
+	* ov-flt-cx-mat.cc (octave_float_complex_matrix::load_ascii): Simplify.
+
 2009-03-20  Jaroslav Hajek  <highegg@gmail.com>
 
 	* ov-re-mat.cc (octave_matrix::isnan, octave_matrix::isinf,
--- a/src/ov-cx-mat.cc
+++ b/src/ov-cx-mat.cc
@@ -353,20 +353,15 @@
 		{
 		  ComplexNDArray tmp(dv);
 
-		  if (tmp.is_empty ())
-		    matrix = tmp;
-		  else
-		    {
-		      is >> tmp;
+                  is >> tmp;
 
-		      if (is)
-			matrix = tmp;
-		      else
-			{
-			  error ("load: failed to load matrix constant");
-			  success = false;
-			}
-		    }
+                  if (is)
+                    matrix = tmp;
+                  else
+                    {
+                      error ("load: failed to load matrix constant");
+                      success = false;
+                    }
 		}
 	      else
 		{
--- a/src/ov-flt-cx-mat.cc
+++ b/src/ov-flt-cx-mat.cc
@@ -342,20 +342,15 @@
 		{
 		  FloatComplexNDArray tmp(dv);
 
-		  if (tmp.is_empty ())
-		    matrix = tmp;
-		  else
-		    {
-		      is >> tmp;
+                  is >> tmp;
 
-		      if (is)
-			matrix = tmp;
-		      else
-			{
-			  error ("load: failed to load matrix constant");
-			  success = false;
-			}
-		    }
+                  if (is)
+                    matrix = tmp;
+                  else
+                    {
+                      error ("load: failed to load matrix constant");
+                      success = false;
+                    }
 		}
 	      else
 		{
--- a/src/ov-flt-re-mat.cc
+++ b/src/ov-flt-re-mat.cc
@@ -372,20 +372,15 @@
 		{
 		  FloatNDArray tmp(dv);
 
-		  if (tmp.is_empty ())
-		    matrix = tmp;
-		  else
-		    {
-		      is >> tmp;
+                  is >> tmp;
 
-		      if (is)
-			matrix = tmp;
-		      else
-			{
-			  error ("load: failed to load matrix constant");
-			  success = false;
-			}
-		    }
+                  if (is)
+                    matrix = tmp;
+                  else
+                    {
+                      error ("load: failed to load matrix constant");
+                      success = false;
+                    }
 		}
 	      else
 		{
--- a/src/ov-re-mat.cc
+++ b/src/ov-re-mat.cc
@@ -380,20 +380,15 @@
 		{
 		  NDArray tmp(dv);
 
-		  if (tmp.is_empty ())
-		    matrix = tmp;
-		  else
-		    {
-		      is >> tmp;
+                  is >> tmp;
 
-		      if (is)
-			matrix = tmp;
-		      else
-			{
-			  error ("load: failed to load matrix constant");
-			  success = false;
-			}
-		    }
+                  if (is)
+                    matrix = tmp;
+                  else
+                    {
+                      error ("load: failed to load matrix constant");
+                      success = false;
+                    }
 		}
 	      else
 		{