Working with igraph in a project, we encounter serious timing issues. Running cProfile on the worst function, we realize that this code takes a lot of time:
[ partition.membership[x.index] if x.index < len(partition.membership) else -1 for x in G.vs ]
where G
is a Graph
.
Looking at the documentation, it appears that membership is a property returning a copy of the membership:
@property
def membership(self):
"""Returns the membership vector."""
return self._membership[:]
Is there a reason for returning an explicit copy and not just self._membership
?
We don't want people messing around with the membership list because then it might go off-sync with other cached properties of the object (like the modularity). If you need this for performance reasons, get the membership list once outside your list comprehension and then use that, or just use self._membership
instead.