Skip to content

Commit

Permalink
FIX: adding 0 to a sparse matrix returns a copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Laxalde committed Feb 29, 2012
1 parent 5092498 commit 4b2eb33
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions scipy/sparse/compressed.py
Expand Up @@ -170,10 +170,10 @@ def __add__(self,other):
# First check if argument is a scalar
if isscalarlike(other):
if other == 0:
return self
return self.copy()
else: # Now we would add this scalar to every element.
raise NotImplementedError('adding a scalar to a sparse'
'matrix is not supported')
raise NotImplementedError('adding a nonzero scalar to a '
'sparse matrix is not supported')
elif isspmatrix(other):
if (other.shape != self.shape):
raise ValueError("inconsistent shapes")
Expand All @@ -192,10 +192,10 @@ def __sub__(self,other):
# First check if argument is a scalar
if isscalarlike(other):
if other == 0:
return self
return self.copy()
else: # Now we would add this scalar to every element.
raise NotImplementedError('adding a scalar to a sparse '
'matrix is not supported')
raise NotImplementedError('adding a nonzero scalar to a '
'sparse matrix is not supported')
elif isspmatrix(other):
if (other.shape != self.shape):
raise ValueError("inconsistent shapes")
Expand All @@ -211,10 +211,10 @@ def __rsub__(self,other): # other - self
#note: this can't be replaced by other + (-self) for unsigned types
if isscalarlike(other):
if other == 0:
return -self
return -self.copy()
else: # Now we would add this scalar to every element.
raise NotImplementedError('adding a scalar to a sparse '
'matrix is not supported')
raise NotImplementedError('adding a nonzero scalar to a '
'sparse matrix is not supported')
elif isdense(other):
# Convert this matrix to a dense matrix and subtract them
return other - self.todense()
Expand Down

0 comments on commit 4b2eb33

Please sign in to comment.