[Scipy-svn] r2132 - trunk/Lib/sparse

scipy-svn at scipy.org scipy-svn at scipy.org
Wed Jul 26 08:38:40 EDT 2006


Author: edschofield
Date: 2006-07-26 07:38:37 -0500 (Wed, 26 Jul 2006)
New Revision: 2132

Modified:
   trunk/Lib/sparse/sparse.py
Log:
Better exception handling for unsupported sparse matrix indexing (ticket #226).

Cast zeros in lil_matrix objects to correct data type.


Modified: trunk/Lib/sparse/sparse.py
===================================================================
--- trunk/Lib/sparse/sparse.py	2006-07-26 10:46:41 UTC (rev 2131)
+++ trunk/Lib/sparse/sparse.py	2006-07-26 12:38:37 UTC (rev 2132)
@@ -2449,6 +2449,8 @@
         elif isinstance(i, int):
             if not (i>=0 and i<self.shape[0]):
                 raise IndexError, "lil_matrix index out of range"
+        elif operator.isSequenceType(i):
+            raise NotImplementedError, "sequence indexing not yet fully supported"
         else:
             raise IndexError, "invalid index"
         row = self.rows[i]
@@ -2467,7 +2469,8 @@
             new.data = [self.data[i][startind:stopind]]
             new.rows = [[colind - start for colind in row[startind:stopind]]]
             return new
-        
+        elif operator.isSequenceType(j):
+            raise NotImplementedError, "sequence indexing not yet fully supported"
         elif isinstance(j, int):
             if not (j>=0 and j<self.shape[1]):
                 raise IndexError, "lil_matrix index out of range"
@@ -2476,7 +2479,7 @@
         pos = bisect_left(row, j)
         if pos == len(row) or row[pos] != j:
             # Element doesn't exist (is zero)
-            return 0.0
+            return self.dtype.type(0)
         else:
             return self.data[i][pos]
     




More information about the Scipy-svn mailing list