[Scipy-svn] r5583 - in trunk/scipy: sparse sparse/tests spatial/tests

scipy-svn at scipy.org scipy-svn at scipy.org
Sat Feb 21 11:57:46 EST 2009


Author: peridot
Date: 2009-02-21 10:57:32 -0600 (Sat, 21 Feb 2009)
New Revision: 5583

Modified:
   trunk/scipy/sparse/dok.py
   trunk/scipy/sparse/tests/test_base.py
   trunk/scipy/spatial/tests/test_kdtree.py
Log:
Fixes bug 859


Modified: trunk/scipy/sparse/dok.py
===================================================================
--- trunk/scipy/sparse/dok.py	2009-02-21 10:12:05 UTC (rev 5582)
+++ trunk/scipy/sparse/dok.py	2009-02-21 16:57:32 UTC (rev 5583)
@@ -218,7 +218,7 @@
                 raise IndexError, "index out of bounds"
 
             if np.isscalar(value):
-                if value==0:
+                if value==0 and self.has_key((i,j)):
                     del self[(i,j)]
                 else:
                     dict.__setitem__(self, (i,j), self.dtype.type(value))

Modified: trunk/scipy/sparse/tests/test_base.py
===================================================================
--- trunk/scipy/sparse/tests/test_base.py	2009-02-21 10:12:05 UTC (rev 5582)
+++ trunk/scipy/sparse/tests/test_base.py	2009-02-21 16:57:32 UTC (rev 5583)
@@ -548,8 +548,18 @@
         assert_equal(toself(copy=False).todense(), A.todense())
 
 
-        #TODO how can we check whether the data is copied?
-        pass
+        # check whether the data is copied?
+        # TODO: deal with non-indexable types somehow
+        B = A.copy()
+        try:
+            B[0,0] += 1
+            assert B[0,0]!=A[0,0]
+        except NotImplementedError:
+            # not all sparse matrices can be indexed
+            pass
+        except TypeError:
+            # not all sparse matrices can be indexed
+            pass
 
     # Eventually we'd like to allow matrix products between dense
     # and sparse matrices using the normal dot() function:
@@ -590,6 +600,7 @@
 class _TestGetSet:
     def test_setelement(self):
         A = self.spmatrix((3,4))
+        A[ 0, 0] = 0 # bug 859
         A[ 1, 2] = 4.0
         A[ 0, 1] = 3
         A[ 2, 0] = 2.0

Modified: trunk/scipy/spatial/tests/test_kdtree.py
===================================================================
--- trunk/scipy/spatial/tests/test_kdtree.py	2009-02-21 10:12:05 UTC (rev 5582)
+++ trunk/scipy/spatial/tests/test_kdtree.py	2009-02-21 16:57:32 UTC (rev 5583)
@@ -403,6 +403,9 @@
         for ((i,j),d) in M.items():
             assert j in r[i]
 
+    def test_zero_distance(self):
+        M = self.T1.sparse_distance_matrix(self.T1, self.r) # raises an exception for bug 859
+
 def test_distance_matrix():
     m = 10
     n = 11




More information about the Scipy-svn mailing list