At the following line, https://github.com/mdeff/cnn_graph/blob/master/lib/coarsening.py#L210, you have the assertion assert len(indices[0] == M), but this is always true, because indices[0] is not empty and indices[0] == M produces another list of the same size as indices[0], so len(indices[0] == M) is always greater than zero.