'Fast multiplication exploiting the sparsity of the matrix.'

def _eval_matrix_mul(self, other):

    if (not isinstance(other, SparseMatrix)):
        return (self * self._new(other))
    row_lookup = defaultdict(dict)
    for ((i, j), val) in self._smat.items():
        row_lookup[i][j] = val
    col_lookup = defaultdict(dict)
    for ((i, j), val) in other._smat.items():
        col_lookup[j][i] = val
    smat = {}
    for row in row_lookup.keys():
        for col in col_lookup.keys():
            indices = (set(col_lookup[col].keys()) & set(row_lookup[row].keys()))
            if indices:
                val = sum(((row_lookup[row][k] * col_lookup[col][k]) for k in indices))
                smat[(row, col)] = val
    return self._new(self.rows, other.cols, smat)
