[Scipy-svn] r3423 - in trunk/scipy/sparse: . tests

scipy-svn@scip... scipy-svn@scip...
Mon Oct 8 04:57:18 CDT 2007


Author: rc
Date: 2007-10-08 04:57:10 -0500 (Mon, 08 Oct 2007)
New Revision: 3423

Modified:
   trunk/scipy/sparse/sparse.py
   trunk/scipy/sparse/tests/test_sparse.py
Log:
issequence() accepts numpy 1D arrays -> those can be used as lil matrix indices.



Modified: trunk/scipy/sparse/sparse.py
===================================================================
--- trunk/scipy/sparse/sparse.py	2007-10-07 06:10:07 UTC (rev 3422)
+++ trunk/scipy/sparse/sparse.py	2007-10-08 09:57:10 UTC (rev 3423)
@@ -2926,4 +2926,5 @@
     return out
 
 def issequence(t):
-    return isinstance(t, (list, tuple))
+    return isinstance(t, (list, tuple))\
+           or (isinstance(t, ndarray) and (t.ndim == 1))

Modified: trunk/scipy/sparse/tests/test_sparse.py
===================================================================
--- trunk/scipy/sparse/tests/test_sparse.py	2007-10-07 06:10:07 UTC (rev 3422)
+++ trunk/scipy/sparse/tests/test_sparse.py	2007-10-08 09:57:10 UTC (rev 3423)
@@ -940,6 +940,19 @@
         B[:2,:2] = csc_matrix(array(block))
         assert_array_equal(B.todense()[:2,:2],block)
 
+    def check_lil_sequence_assignement(self):
+        A = lil_matrix((4,3))
+        B = lil_eye((3,4))
+
+        i0 = [0,1,2]
+        i1 = (0,1,2)
+        i2 = array( i0 )
+
+        A[0,i0] = B[i0,0]
+        A[1,i1] = B[i1,1]
+        A[2,i2] = B[i2,2]
+        assert_array_equal(A.todense(),B.T.todense())
+
     def check_lil_iteration(self):
         row_data = [[1,2,3],[4,5,6]]
         B = lil_matrix(array(row_data))



More information about the Scipy-svn mailing list