[Scipy-svn] r3190 - trunk/Lib/sparse
scipy-svn at scipy.org
scipy-svn at scipy.org
Wed Jul 25 13:27:47 EDT 2007
Author: wnbell
Date: 2007-07-25 12:27:45 -0500 (Wed, 25 Jul 2007)
New Revision: 3190
Modified:
trunk/Lib/sparse/sparse.py
Log:
fixed subtraction between sparse & dense
resolves ticket #466
Modified: trunk/Lib/sparse/sparse.py
===================================================================
--- trunk/Lib/sparse/sparse.py 2007-07-25 05:57:03 UTC (rev 3189)
+++ trunk/Lib/sparse/sparse.py 2007-07-25 17:27:45 UTC (rev 3190)
@@ -517,7 +517,8 @@
other.indptr, other.indices, other.data)
return self.__class__((data, ind, indptr), dims=out_shape, check=False)
- def __addsub(self, other, fn):
+
+ def __add__(self,other,fn):
# First check if argument is a scalar
if isscalarlike(other):
# Now we would add this scalar to every element.
@@ -529,15 +530,26 @@
return self._binopt(other,fn)
elif isdense(other):
# Convert this matrix to a dense matrix and add them
- return other + self.todense()
+ return self.todense() + other
else:
raise NotImplemented
-
- def __add__(self,other,fn):
- return self.__addsub(other,fn)
def __sub__(self,other,fn):
- return self.__addsub(other,fn)
+ # First check if argument is a scalar
+ if isscalarlike(other):
+ # Now we would add this scalar to every element.
+ raise NotImplementedError, 'adding a scalar to a CSC or CSR ' \
+ 'matrix is not supported'
+ elif isspmatrix(other):
+ if (other.shape != self.shape):
+ raise ValueError, "inconsistent shapes"
+ return self._binopt(other,fn)
+ elif isdense(other):
+ # Convert this matrix to a dense matrix and add them
+ return self.todense() - other
+ else:
+ raise NotImplemented
+
def __mul__(self, other): # self * other
""" Scalar, vector, or matrix multiplication
More information about the Scipy-svn
mailing list