'apply the binary operation fn to two sparse matrices.'

def _binopt(self, other, op):

    other = self.__class__(other)
    fn = getattr(_sparsetools, ((self.format + op) + self.format))
    maxnnz = (self.nnz + other.nnz)
    idx_dtype = get_index_dtype((self.indptr, self.indices, other.indptr, other.indices), maxval=maxnnz)
    indptr = np.empty(self.indptr.shape, dtype=idx_dtype)
    indices = np.empty(maxnnz, dtype=idx_dtype)
    bool_ops = ['_ne_', '_lt_', '_gt_', '_le_', '_ge_']
    if (op in bool_ops):
        data = np.empty(maxnnz, dtype=np.bool_)
    else:
        data = np.empty(maxnnz, dtype=upcast(self.dtype, other.dtype))
    fn(self.shape[0], self.shape[1], np.asarray(self.indptr, dtype=idx_dtype), np.asarray(self.indices, dtype=idx_dtype), self.data, np.asarray(other.indptr, dtype=idx_dtype), np.asarray(other.indices, dtype=idx_dtype), other.data, indptr, indices, data)
    A = self.__class__((data, indices, indptr), shape=self.shape)
    A.prune()
    return A
