cnn_graph icon indicating copy to clipboard operation
cnn_graph copied to clipboard

An assertion in the method compute_perm is not doing what it should do

Open nbro opened this issue 5 years ago • 3 comments

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.

nbro avatar Apr 21 '19 21:04 nbro

Thanks. It should be assert len(indices[0]) == M right?

mdeff avatar Jul 20 '20 17:07 mdeff

@mdeff To be honest, I don't know. It's been a long time since I tried it.

nbro avatar Jul 20 '20 20:07 nbro

Me too 🙈

For reference, here's what I have from a later iteration of this code:

def test_permutations():
    parents = [np.array([4, 1, 1, 2, 2, 3, 0, 0, 3]),
               np.array([2, 1, 0, 1, 0])]
    permutations = compute_permutations(parents)
    assert permutations[0] == [3, 4, 0, 9, 1, 2, 5, 8, 6, 7, 10, 11]
    assert permutations[1] == [2, 4, 1, 3, 0, 5]
    assert permutations[2] == [0, 1, 2]
test_permutations()

adjacency = sparse.random(100, 100, density=0.01, format='csr')
adjacency = adjacency + adjacency.T

def test_permutations(adjacency, levels):
    _, parents = coarsen(adjacency, levels)
    permutations = compute_permutations(parents)
    n_nodes = len(permutations[0])
    for level in range(levels):
        n_nodes_level = n_nodes // 2**level
        assert sorted(permutations[level]) == list(range(n_nodes_level))
test_permutations(adjacency, levels=5)

mdeff avatar Jul 20 '20 23:07 mdeff