Skip to content

Commit 1fb49d7

Browse files
committed
try an idea
1 parent 2b692a1 commit 1fb49d7

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Diff for: src/sage/combinat/posets/posets.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -5232,7 +5232,7 @@ def factor(self):
52325232
"""
52335233
Factor the poset as a Cartesian product of smaller posets.
52345234
5235-
This only works for connected posets for the moment.
5235+
This only works for connected posets.
52365236
52375237
The decomposition of a connected poset as a Cartesian product
52385238
of posets (prime in the sense that they cannot be written as
@@ -5309,22 +5309,23 @@ def factor(self):
53095309
is_product, dic = G.is_cartesian_product(relabeling=True)
53105310
if not is_product:
53115311
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()}
53135313

53145314
prod_dg = dg.relabel(dic, inplace=False)
53155315
v0 = next(iter(dic.values()))
53165316
n = len(v0)
53175317
factors_range = range(n)
53185318

53195319
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
53285329

53295330
fusion_edges = []
53305331
for i0, i1 in Subsets(factors_range, 2):

0 commit comments

Comments
 (0)