diff liboctave/dSparse.cc @ 9469:c6edba80dfae

sanity checks for loading sparse matrices
author John W. Eaton <jwe@octave.org>
date Wed, 29 Jul 2009 12:15:27 -0400
parents 5d46c4a894e8
children a5035bc7fbfb
line wrap: on
line diff
--- a/liboctave/dSparse.cc	Wed Jul 29 07:22:05 2009 -0400
+++ b/liboctave/dSparse.cc	Wed Jul 29 12:15:27 2009 -0400
@@ -7584,48 +7584,9 @@
 std::istream&
 operator >> (std::istream& is, SparseMatrix& a)
 {
-  octave_idx_type nr = a.rows ();
-  octave_idx_type nc = a.cols ();
-  octave_idx_type nz = a.nzmax ();
-
-  if (nr > 0 && nc > 0)
-    {
-      octave_idx_type itmp, jtmp, jold = 0;
-      double tmp;
-      octave_idx_type ii = 0;
-       
-      a.cidx (0) = 0;
-      for (octave_idx_type i = 0; i < nz; i++)
-	{
-	  is >> itmp;
-	  itmp--;
-	  is >> jtmp;
-	  jtmp--;
-	  tmp = octave_read_double (is);
-	  
-	  if (is)
-	    {
-	      if (jold != jtmp)
-		{
-		  for (octave_idx_type j = jold; j < jtmp; j++)
-		    a.cidx(j+1) = ii;
-		  
-		  jold = jtmp;
-		}
-	      a.data (ii) = tmp;
-	      a.ridx (ii++) = itmp;
-	    }
-	  else
-	    goto done;
-	}
-
-      for (octave_idx_type j = jold; j < nc; j++)
-	a.cidx(j+1) = ii;
-    }
-  
- done:
-
-  return is;
+  typedef SparseMatrix::element_type elt_type;
+
+  return read_sparse_matrix<elt_type> (is, a, octave_read_value<double>);
 }
 
 SparseMatrix