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

scipy-svn at scipy.org scipy-svn at scipy.org
Mon Dec 17 23:37:39 EST 2007


Author: wnbell
Date: 2007-12-17 22:37:30 -0600 (Mon, 17 Dec 2007)
New Revision: 3682

Modified:
   trunk/scipy/sparse/base.py
   trunk/scipy/sparse/compressed.py
   trunk/scipy/sparse/tests/test_base.py
Log:
added .multiply() for pointwise multiplication


Modified: trunk/scipy/sparse/base.py
===================================================================
--- trunk/scipy/sparse/base.py	2007-12-18 04:06:01 UTC (rev 3681)
+++ trunk/scipy/sparse/base.py	2007-12-18 04:37:30 UTC (rev 3682)
@@ -208,6 +208,11 @@
 
     def __rsub__(self, other):  # other - self
         return self.tocsr().__rsub__(other)
+    
+    def multiply(self, other):
+        """Point-wise multiplication by another matrix
+        """
+        return self.tocsr().multiply(other)
 
     def __mul__(self, other):
         return self.tocsr().__mul__(other)

Modified: trunk/scipy/sparse/compressed.py
===================================================================
--- trunk/scipy/sparse/compressed.py	2007-12-18 04:06:01 UTC (rev 3681)
+++ trunk/scipy/sparse/compressed.py	2007-12-18 04:37:30 UTC (rev 3682)
@@ -285,11 +285,24 @@
         elif isspmatrix(other):
             if (other.shape != self.shape):
                 raise ValueError, "inconsistent shapes"
-            
+           
+            warn("use .multiply(other) for elementwise multiplication", \
+                    DeprecationWarning)
             return self._binopt(other,'_elmul_')
         else:
             raise NotImplementedError
+    
+    def multiply(self, other):
+        """Point-wise multiplication by another matrix
+        """
+        if (other.shape != self.shape):
+            raise ValueError, "inconsistent shapes"
 
+        if isdense(other):
+            return multiply(self.todense(),other)
+        else:
+            other = self.__class__(other)
+            return self._binopt(other,'_elmul_')
 
     def matmat(self, other):
         if isspmatrix(other):

Modified: trunk/scipy/sparse/tests/test_base.py
===================================================================
--- trunk/scipy/sparse/tests/test_base.py	2007-12-18 04:06:01 UTC (rev 3681)
+++ trunk/scipy/sparse/tests/test_base.py	2007-12-18 04:37:30 UTC (rev 3682)
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 #
 # Authors: Travis Oliphant, Ed Schofield, Robert Cimrman, Nathan Bell, and others
 
@@ -151,7 +150,7 @@
         temp = self.dat.copy()
         temp[0,2] = 2.0
         temp = self.spmatrix(temp)
-        c = temp ** self.datsp 
+        c = temp.multiply(self.datsp)
         assert_array_equal(c.todense(),[[1,0,0,4],[9,0,1,0],[0,4,0,0]])
 
     def check_eldiv(self):




More information about the Scipy-svn mailing list