cnn_graph
cnn_graph copied to clipboard
An assertion in the method compute_perm is not doing what it should do
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.
Thanks. It should be assert len(indices[0]) == M
right?
@mdeff To be honest, I don't know. It's been a long time since I tried it.
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)