'Convert this matrix to COOrdinate format.
When copy=False the data array will be shared between
this matrix and the resultant coo_matrix.'

def tocoo(self, copy=True):

    (M, N) = self.shape
    (R, C) = self.blocksize
    indptr_diff = np.diff(self.indptr)
    if (indptr_diff.dtype.itemsize > np.dtype(np.intp).itemsize):
        indptr_diff_limited = indptr_diff.astype(np.intp)
        if np.any((indptr_diff_limited != indptr_diff)):
            raise ValueError('Matrix    too    big    to    convert')
        indptr_diff = indptr_diff_limited
    row = (R * np.arange((M // R))).repeat(indptr_diff)
    row = row.repeat((R * C)).reshape((-1), R, C)
    row += np.tile(np.arange(R).reshape((-1), 1), (1, C))
    row = row.reshape((-1))
    col = (C * self.indices).repeat((R * C)).reshape((-1), R, C)
    col += np.tile(np.arange(C), (R, 1))
    col = col.reshape((-1))
    data = self.data.reshape((-1))
    if copy:
        data = data.copy()
    from .coo import coo_matrix
    return coo_matrix((data, (row, col)), shape=self.shape)
