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)

_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to