'Eliminate duplicate matrix entries by adding them together
The is an *in place* operation'

def sum_duplicates(self):

    if self.has_canonical_format:
        return
    self.sort_indices()
    (R, C) = self.blocksize
    (M, N) = self.shape
    n_row = (M // R)
    nnz = 0
    row_end = 0
    for i in range(n_row):
        jj = row_end
        row_end = self.indptr[(i + 1)]
        while (jj < row_end):
            j = self.indices[jj]
            x = self.data[jj]
            jj += 1
            while ((jj < row_end) and (self.indices[jj] == j)):
                x += self.data[jj]
                jj += 1
            self.indices[nnz] = j
            self.data[nnz] = x
            nnz += 1
        self.indptr[(i + 1)] = nnz
    self.prune()
    self.has_canonical_format = True
