scipy 0.5.2, in scipy.sparse.lil_matrix.__mul__: the optimization for when multiplying by zero scalar is flawed. A copy of the original matrix is returned, rather than the correct zero matrix. Nasty bug because it only manifests itself with special input (zero scalar), took me some time to nail my unexpected program output down to this :( Easily resolved by rewriting the function, e.g. def __mul__(self, other): # self * other if isscalarlike(other): if other == 0: # Multiply by zero: return the zero matrix return lil_matrix(self.shape, dtype = self.dtype) # Multiply this scalar by every element. new = self.copy() new.data = [[val * other for val in rowvals] for rowvals in new.data] return new else: return self.dot(other)
On Tue, May 01, 2007 at 05:36:19PM -0700, koara wrote:
scipy 0.5.2, in scipy.sparse.lil_matrix.__mul__: the optimization for when multiplying by zero scalar is flawed. A copy of the original matrix is returned, rather than the correct zero matrix. Nasty bug because it only manifests itself with special input (zero scalar), took me some time to nail my unexpected program output down to this :(
You're right -- that *is* nasty! Fixed in r2951. Thanks for the report! http://projects.scipy.org/scipy/scipy/changeset/2951 Cheers Stéfan
participants (2)
-
koara
-
Stefan van der Walt