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

scipy-svn@scip... scipy-svn@scip...
Fri Oct 10 12:13:14 CDT 2008


Author: wnbell
Date: 2008-10-10 12:13:10 -0500 (Fri, 10 Oct 2008)
New Revision: 4792

Modified:
   trunk/scipy/sparse/csr.py
   trunk/scipy/sparse/sputils.py
   trunk/scipy/sparse/tests/test_base.py
   trunk/scipy/sparse/tests/test_sputils.py
Log:
fix CSR[:,array([1,2])] slicing problem


Modified: trunk/scipy/sparse/csr.py
===================================================================
--- trunk/scipy/sparse/csr.py	2008-10-10 07:02:20 UTC (rev 4791)
+++ trunk/scipy/sparse/csr.py	2008-10-10 17:13:10 UTC (rev 4792)
@@ -338,7 +338,7 @@
 
                 return i0, i1
 
-            elif isscalar( sl ):
+            elif isintlike( sl ):
                 if sl < 0:
                     sl += num
 

Modified: trunk/scipy/sparse/sputils.py
===================================================================
--- trunk/scipy/sparse/sputils.py	2008-10-10 07:02:20 UTC (rev 4791)
+++ trunk/scipy/sparse/sputils.py	2008-10-10 17:13:10 UTC (rev 4792)
@@ -82,13 +82,16 @@
     """Is x appropriate as an index into a sparse matrix? Returns True
     if it can be cast safely to a machine int.
     """
-    try:
-        if int(x) == x:
-            return True
-        else:
+    if issequence(x):
+        return False
+    else:
+        try:
+            if int(x) == x:
+                return True
+            else:
+                return False
+        except TypeError:
             return False
-    except TypeError:
-        return False
 
 def isshape(x):
     """Is x a valid 2-tuple of dimensions?

Modified: trunk/scipy/sparse/tests/test_base.py
===================================================================
--- trunk/scipy/sparse/tests/test_base.py	2008-10-10 07:02:20 UTC (rev 4791)
+++ trunk/scipy/sparse/tests/test_base.py	2008-10-10 17:13:10 UTC (rev 4792)
@@ -700,20 +700,28 @@
         assert_equal(A[2,3],  B[2,3])
         assert_equal(A[-1,8], B[-1,8])
         assert_equal(A[-1,-2],B[-1,-2])
+        assert_equal(A[array(-1),-2],B[-1,-2])
+        assert_equal(A[-1,array(-2)],B[-1,-2])
+        assert_equal(A[array(-1),array(-2)],B[-1,-2])
 
         # [i,1:2]
         assert_equal(A[2,:].todense(),   B[2,:])
         assert_equal(A[2,5:-2].todense(),B[2,5:-2])
+        assert_equal(A[array(2),5:-2].todense(),B[2,5:-2])
 
         # [i,[1,2]]
         assert_equal(A[3,[1,3]].todense(),  B[3,[1,3]])
         assert_equal(A[-1,[2,-5]].todense(),B[-1,[2,-5]])
+        assert_equal(A[array(-1),[2,-5]].todense(),B[-1,[2,-5]])
+        assert_equal(A[-1,array([2,-5])].todense(),B[-1,[2,-5]])
+        assert_equal(A[array(-1),array([2,-5])].todense(),B[-1,[2,-5]])
 
         # [1:2,j]
         assert_equal(A[:,2].todense(),   B[:,2])
         assert_equal(A[3:4,9].todense(), B[3:4,9])
         assert_equal(A[1:4,-5].todense(),B[1:4,-5])
         assert_equal(A[2:-1,3].todense(),B[2:-1,3])
+        assert_equal(A[2:-1,array(3)].todense(),B[2:-1,3])
 
         # [1:2,1:2]
         assert_equal(A[1:2,1:2].todense(),B[1:2,1:2])
@@ -725,26 +733,38 @@
         assert_equal(A[:,[2,8,3,-1]].todense(),B[:,[2,8,3,-1]])
         assert_equal(A[3:4,[9]].todense(),     B[3:4,[9]])
         assert_equal(A[1:4,[-1,-5]].todense(), B[1:4,[-1,-5]])
+        assert_equal(A[1:4,array([-1,-5])].todense(), B[1:4,[-1,-5]])
 
         # [[1,2],j]
         assert_equal(A[[1,3],3].todense(),   B[[1,3],3])
         assert_equal(A[[2,-5],-4].todense(), B[[2,-5],-4])
+        assert_equal(A[array([2,-5]),-4].todense(), B[[2,-5],-4])
+        assert_equal(A[[2,-5],array(-4)].todense(), B[[2,-5],-4])
+        assert_equal(A[array([2,-5]),array(-4)].todense(), B[[2,-5],-4])
 
         # [[1,2],1:2]
         assert_equal(A[[1,3],:].todense(),    B[[1,3],:])
         assert_equal(A[[2,-5],8:-1].todense(),B[[2,-5],8:-1])
+        assert_equal(A[array([2,-5]),8:-1].todense(),B[[2,-5],8:-1])
 
         # [[1,2],[1,2]]
         assert_equal(A[[1,3],[2,4]],   B[[1,3],[2,4]])
         assert_equal(A[[-1,-3],[2,-4]],B[[-1,-3],[2,-4]])
+        assert_equal(A[array([-1,-3]),[2,-4]],B[[-1,-3],[2,-4]])
+        assert_equal(A[[-1,-3],array([2,-4])],B[[-1,-3],[2,-4]])
+        assert_equal(A[array([-1,-3]),array([2,-4])],B[[-1,-3],[2,-4]])
 
         # [[[1],[2]],[1,2]]
         assert_equal(A[[[1],[3]],[2,4]].todense(),        B[[[1],[3]],[2,4]])
         assert_equal(A[[[-1],[-3],[-2]],[2,-4]].todense(),B[[[-1],[-3],[-2]],[2,-4]])
+        assert_equal(A[array([[-1],[-3],[-2]]),[2,-4]].todense(),B[[[-1],[-3],[-2]],[2,-4]])
+        assert_equal(A[[[-1],[-3],[-2]],array([2,-4])].todense(),B[[[-1],[-3],[-2]],[2,-4]])
+        assert_equal(A[array([[-1],[-3],[-2]]),array([2,-4])].todense(),B[[[-1],[-3],[-2]],[2,-4]])
 
         # [i]
         assert_equal(A[1,:].todense(), B[1,:])
         assert_equal(A[-2,:].todense(),B[-2,:])
+        assert_equal(A[array(-2),:].todense(),B[-2,:])
 
         # [1:2]
         assert_equal(A[1:4].todense(), B[1:4])
@@ -753,14 +773,17 @@
         # [[1,2]]
         assert_equal(A[[1,3]].todense(),  B[[1,3]])
         assert_equal(A[[-1,-3]].todense(),B[[-1,-3]])
+        assert_equal(A[array([-1,-3])].todense(),B[[-1,-3]])
 
         # [[1,2],:][:,[1,2]]
         assert_equal(A[[1,3],:][:,[2,4]].todense(),    B[[1,3],:][:,[2,4]]    )
         assert_equal(A[[-1,-3],:][:,[2,-4]].todense(), B[[-1,-3],:][:,[2,-4]] )
+        assert_equal(A[array([-1,-3]),:][:,array([2,-4])].todense(), B[[-1,-3],:][:,[2,-4]] )
 
         # [:,[1,2]][[1,2],:]
         assert_equal(A[:,[1,3]][[2,4],:].todense(),    B[:,[1,3]][[2,4],:]    )
         assert_equal(A[:,[-1,-3]][[2,-4],:].todense(), B[:,[-1,-3]][[2,-4],:] )
+        assert_equal(A[:,array([-1,-3])][array([2,-4]),:].todense(), B[:,[-1,-3]][[2,-4],:] )
 
 
         # Check bug reported by Robert Cimrman:

Modified: trunk/scipy/sparse/tests/test_sputils.py
===================================================================
--- trunk/scipy/sparse/tests/test_sputils.py	2008-10-10 07:02:20 UTC (rev 4791)
+++ trunk/scipy/sparse/tests/test_sputils.py	2008-10-10 17:13:10 UTC (rev 4792)
@@ -36,7 +36,7 @@
         assert_equal(isintlike(3.0),True)
         assert_equal(isintlike(-4),True)
         assert_equal(isintlike(np.array(3)),True)
-        assert_equal(isintlike( np.array([3])), True)
+        assert_equal(isintlike(np.array([3])), False)
 
         assert_equal(isintlike(2.5),False)
         assert_equal(isintlike(1 + 3j),False)



More information about the Scipy-svn mailing list