Skip to content

Commit

Permalink
add switch for n > 16
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Oct 10, 2024
1 parent 8b55fc3 commit 93c0c8b
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/sage/combinat/posets/posets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8930,22 +8930,35 @@ def __contains__(self, P) -> bool:
return P in FinitePosets() and P.cardinality() == self._n

def __iter__(self):
"""
r"""
Return an iterator of representatives of the isomorphism classes
of finite posets of a given size.
.. NOTE::
This uses an iterator from ``nauty`` as a backend to construct
transitively-reduced, acyclic digraphs.
If the size `n\leq 16`, this uses an iterator from
``nauty`` as a backend to construct only transitively-reduced,
acyclic digraphs. Otherwise it uses a slow naive iterator,
as the ``nauty`` iterator is not available.
EXAMPLES::
sage: P = Posets(2)
sage: list(P)
[Finite poset containing 2 elements, Finite poset containing 2 elements]
TESTS::
sage: it = iter(Posets(17))
sage: next(it)
Finite poset containing 17 elements
"""
for dig in digraphs.nauty_posetg(f"{self._n} o"):
if self._n <= 16:
it = digraphs.nauty_posetg(f"{self._n} o")
else:
it = digraphs(self._n, is_poset)

for dig in it:
# We need to relabel the digraph since range(self._n) must be a linear
# extension. Too bad we need to compute this again. TODO: Fix this.
label_dict = dict(zip(dig.topological_sort(), range(dig.order())))
Expand Down

0 comments on commit 93c0c8b

Please sign in to comment.