@@ -158,7 +158,7 @@ def union(graphs, byname="auto"):
158158 raise RuntimeError (
159159 f"Some graphs are not named (got { n_named } named, { ngr - n_named } unnamed)"
160160 )
161- # Now we know that byname is only used is all graphs are named
161+ # Now we know that byname is only used if all graphs are named
162162
163163 # Trivial cases
164164 if ngr == 0 :
@@ -184,7 +184,12 @@ def union(graphs, byname="auto"):
184184 # Reorder vertices to match uninames
185185 # vertex k -> p[k]
186186 permutation = [permutation_map [x ] for x in ng .vs ["name" ]]
187- ng = ng .permute_vertices (permutation )
187+
188+ # permute_vertices() needs the inverse permutation
189+ inv_permutation = [0 ] * len (permutation )
190+ for i , x in enumerate (permutation ):
191+ inv_permutation [x ] = i
192+ ng = ng .permute_vertices (inv_permutation )
188193
189194 newgraphs .append (ng )
190195 else :
@@ -353,7 +358,7 @@ def intersection(graphs, byname="auto", keep_all_vertices=True):
353358 raise RuntimeError (
354359 f"Some graphs are not named (got { n_named } named, { ngr - n_named } unnamed)"
355360 )
356- # Now we know that byname is only used is all graphs are named
361+ # Now we know that byname is only used if all graphs are named
357362
358363 # Trivial cases
359364 if ngr == 0 :
@@ -389,7 +394,12 @@ def intersection(graphs, byname="auto", keep_all_vertices=True):
389394 # Reorder vertices to match uninames
390395 # vertex k -> p[k]
391396 permutation = [permutation_map [x ] for x in ng .vs ["name" ]]
392- ng = ng .permute_vertices (permutation )
397+
398+ # permute_vertices() needs the inverse permutation
399+ inv_permutation = [0 ] * len (permutation )
400+ for i , x in enumerate (permutation ):
401+ inv_permutation [x ] = i
402+ ng = ng .permute_vertices (inv_permutation )
393403
394404 newgraphs .append (ng )
395405 else :
0 commit comments