[Scipy-svn] r3762 - in trunk/scipy/io: . matlab

scipy-svn at scipy.org scipy-svn at scipy.org
Wed Jan 2 00:37:21 EST 2008


Author: wnbell
Date: 2008-01-01 23:37:17 -0600 (Tue, 01 Jan 2008)
New Revision: 3762

Modified:
   trunk/scipy/io/matlab/mio5.py
   trunk/scipy/io/mmio.py
Log:
fixed small bug in MATLAB 6 sparse reader
updated use of sparse dims parameter


Modified: trunk/scipy/io/matlab/mio5.py
===================================================================
--- trunk/scipy/io/matlab/mio5.py	2008-01-02 04:07:30 UTC (rev 3761)
+++ trunk/scipy/io/matlab/mio5.py	2008-01-02 05:37:17 UTC (rev 3762)
@@ -359,19 +359,24 @@
             data = self.read_element()
         ''' From the matlab (TM) API documentation, last found here:
         http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/
-        rowind are simply the row indices for all the (res) non-zero
+        rowind are simply the row indices for all the (nnz) non-zero
         entries in the sparse array.  rowind has nzmax entries, so
-        may well have more entries than len(res), the actual number
-        of non-zero entries, but rowind[len(res):] can be discarded
+        may well have more entries than nnz, the actual number
+        of non-zero entries, but rowind[nnz:] can be discarded
         and should be 0. indptr has length (number of columns + 1),
         and is such that, if D = diff(colind), D[j] gives the number
         of non-zero entries in column j. Because rowind values are
         stored in column order, this gives the column corresponding to
         each rowind
         '''
+        M,N = self.header['dims']
+        indptr = indptr[:N+1]
+        nnz = indptr[-1]
+        rowind = rowind[:nnz]
+        data   = data[:nnz]
         if have_sparse:
-            dims = self.header['dims']
-            return scipy.sparse.csc_matrix((data,rowind,indptr), dims)
+            from scipy.sparse import csc_matrix
+            return csc_matrix((data,rowind,indptr), shape=(M,N))
         else:
             return (dims, data, rowind, indptr)
 

Modified: trunk/scipy/io/mmio.py
===================================================================
--- trunk/scipy/io/mmio.py	2008-01-02 04:07:30 UTC (rev 3761)
+++ trunk/scipy/io/mmio.py	2008-01-02 05:37:17 UTC (rev 3762)
@@ -430,7 +430,7 @@
 
                 V = concatenate((V,od_V))
 
-            a = coo_matrix((V, (I, J)), dims=(rows, cols), dtype=dtype)
+            a = coo_matrix((V, (I, J)), shape=(rows, cols), dtype=dtype)
         else:
             raise NotImplementedError,`format`
 




More information about the Scipy-svn mailing list