@@ -5232,7 +5232,7 @@ def factor(self):
5232
5232
"""
5233
5233
Factor the poset as a Cartesian product of smaller posets.
5234
5234
5235
- This only works for connected posets for the moment .
5235
+ This only works for connected posets.
5236
5236
5237
5237
The decomposition of a connected poset as a Cartesian product
5238
5238
of posets (prime in the sense that they cannot be written as
@@ -5309,22 +5309,23 @@ def factor(self):
5309
5309
is_product , dic = G .is_cartesian_product (relabeling = True )
5310
5310
if not is_product :
5311
5311
return [self ]
5312
- dic = {key : tuple (flatten (dic [ key ] )) for key in dic }
5312
+ dic = {key : tuple (flatten (val )) for key , val in dic . items () }
5313
5313
5314
5314
prod_dg = dg .relabel (dic , inplace = False )
5315
5315
v0 = next (iter (dic .values ()))
5316
5316
n = len (v0 )
5317
5317
factors_range = range (n )
5318
5318
5319
5319
def edge_color (va , vb ):
5320
- for i in range (n ):
5321
- if va [i ] != vb [i ]:
5322
- return i
5323
-
5324
- neighbors_table = {x : [[y for y in prod_dg .neighbor_iterator (x )
5325
- if edge_color (x , y ) == i ]
5326
- for i in factors_range ]
5327
- for x in prod_dg }
5320
+ return next (i for i , (vai , vbi ) in enumerate (zip (va , vb ))
5321
+ if vai != vbi )
5322
+
5323
+ neighbors_table = {}
5324
+ for x in prod_dg :
5325
+ z = [[] for _ in range (n )]
5326
+ for y in prod_dg .neighbor_iterator (x ):
5327
+ z [edge_color (x , y )].append (y )
5328
+ neighbors_table [x ] = z
5328
5329
5329
5330
fusion_edges = []
5330
5331
for i0 , i1 in Subsets (factors_range , 2 ):
0 commit comments