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

scipy-svn at scipy.org scipy-svn at scipy.org
Mon Jun 2 22:00:13 EDT 2008


Author: wnbell
Date: 2008-06-02 21:00:08 -0500 (Mon, 02 Jun 2008)
New Revision: 4403

Modified:
   trunk/scipy/sparse/compressed.py
   trunk/scipy/sparse/tests/test_base.py
Log:
fixed missing import of numpy.multiply
resolves ticket #680


Modified: trunk/scipy/sparse/compressed.py
===================================================================
--- trunk/scipy/sparse/compressed.py	2008-05-31 00:15:46 UTC (rev 4402)
+++ trunk/scipy/sparse/compressed.py	2008-06-03 02:00:08 UTC (rev 4403)
@@ -251,11 +251,13 @@
     def __truediv__(self,other):
         if isscalarlike(other):
             return self * (1./other)
+
         elif isspmatrix(other):
-            if (other.shape != self.shape):
-                raise ValueError, "inconsistent shapes"
+            if other.shape != self.shape:
+                raise ValueError('inconsistent shapes')
 
             return self._binopt(other,'_eldiv_')
+
         else:
             raise NotImplementedError
 
@@ -263,11 +265,11 @@
     def multiply(self, other):
         """Point-wise multiplication by another matrix
         """
-        if (other.shape != self.shape):
-            raise ValueError, "inconsistent shapes"
+        if other.shape != self.shape:
+            raise ValueError('inconsistent shapes')
 
         if isdense(other):
-            return multiply(self.todense(),other)
+            return numpy.multiply(self.todense(),other)
         else:
             other = self.__class__(other)
             return self._binopt(other,'_elmul_')

Modified: trunk/scipy/sparse/tests/test_base.py
===================================================================
--- trunk/scipy/sparse/tests/test_base.py	2008-05-31 00:15:46 UTC (rev 4402)
+++ trunk/scipy/sparse/tests/test_base.py	2008-06-03 02:00:08 UTC (rev 4403)
@@ -215,19 +215,27 @@
         assert_array_equal(self.datsp - A.todense(),self.dat - A.todense())
 
     def test_elmul(self):
-        temp = self.dat.copy()
-        temp[0,2] = 2.0
-        temp = self.spmatrix(temp)
-        c = temp.multiply(self.datsp)
-        assert_array_equal(c.todense(),[[1,0,0,4],[9,0,1,0],[0,4,0,0]])
-
-        # complex
-        A = array([[1-2j,0+5j,-1+0j],[4-3j,-3+6j,5]])
-        B = array([[5+2j,7-3j,-2+1j],[0-1j,-4+2j,9]])
+        # real/real
+        A = array([[4,0,9],[2,-3,5]])
+        B = array([[0,7,0],[0,-4,0]])
         Asp = self.spmatrix(A)
         Bsp = self.spmatrix(B)
-        assert_almost_equal( Asp.multiply(Bsp).todense(), A*B)
+        assert_almost_equal( Asp.multiply(Bsp).todense(), A*B) #sparse/sparse
+        assert_almost_equal( Asp.multiply(B),             A*B) #sparse/dense
 
+        # complex/complex
+        C = array([[1-2j,0+5j,-1+0j],[4-3j,-3+6j,5]])
+        D = array([[5+2j,7-3j,-2+1j],[0-1j,-4+2j,9]])
+        Csp = self.spmatrix(C)
+        Dsp = self.spmatrix(D)
+        assert_almost_equal( Csp.multiply(Dsp).todense(), C*D) #sparse/sparse
+        assert_almost_equal( Csp.multiply(D),             C*D) #sparse/dense
+
+        # real/complex
+        assert_almost_equal( Asp.multiply(Dsp).todense(), A*D) #sparse/sparse
+        assert_almost_equal( Asp.multiply(D),             A*D) #sparse/dense
+        
+
     def test_eldiv(self):
         expected = [[1,0,0,1],[1,0,1,0],[0,1,0,0]]
         assert_array_equal((self.datsp / self.datsp).todense(),expected)




More information about the Scipy-svn mailing list