Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor annotation details in posets to please mypy #39252

Merged
merged 3 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/sage/combinat/posets/hasse_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -2101,14 +2101,14 @@ def orthocomplementations_iterator(self):
for e in orbit:
orbit_number[e] = ind

comps = [None] * n
mt = self.meet_matrix()
jn = self.join_matrix()
for e in range(n):
# Fix following after issue #20727
comps[e] = [x for x in range(n) if
mt[e, x] == 0 and jn[e, x] == n - 1 and
x in orbits[orbit_number[dual_isomorphism[e]]]]

# Fix following after issue #20727
comps = [[x for x in range(n)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to change the order of the items in comps ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, c'est vrai que c'est pas si clair...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

voila, ca doit etre mieux comme ca.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il me sembla aussi.

if mt[e, x] == 0 and jn[e, x] == n - 1 and
x in orbits[orbit_number[dual_e]]]
for e, dual_e in dual_isomorphism.items()]

# Fitting is done by this recursive function:
def recursive_fit(orthocomplements, unbinded):
Expand Down
10 changes: 5 additions & 5 deletions src/sage/combinat/posets/incidence_algebras.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************
from copy import copy
from typing import Any

from sage.misc.cachefunc import cached_method
from sage.misc.lazy_attribute import lazy_attribute
Expand All @@ -19,8 +21,6 @@
from sage.combinat.free_module import CombinatorialFreeModule
from sage.matrix.matrix_space import MatrixSpace

from copy import copy


class IncidenceAlgebra(CombinatorialFreeModule):
r"""
Expand Down Expand Up @@ -449,7 +449,7 @@ def __init__(self, I, prefix='R') -> None:
sage: TestSuite(R).run() # long time
"""
self._ambient = I
EC = {}
EC: dict[Any, list] = {}
P = self._ambient._poset
if not P.is_finite():
raise NotImplementedError("only implemented for finite posets")
Expand All @@ -463,8 +463,8 @@ def __init__(self, I, prefix='R') -> None:
break
if not added:
EC[S] = [i]
self._equiv_classes = map(sorted, EC.values())
self._equiv_classes = {cls[0]: cls for cls in self._equiv_classes}
equiv_classes = map(sorted, EC.values())
self._equiv_classes = {cls[0]: cls for cls in equiv_classes}
cat = Algebras(I.base_ring()).FiniteDimensional().WithBasis()
CombinatorialFreeModule.__init__(self, I.base_ring(),
sorted(self._equiv_classes.keys()),
Expand Down
8 changes: 4 additions & 4 deletions src/sage/combinat/posets/linear_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,12 @@ def cardinality(self):
for x in range(n):
# Use the existing Jup table to compute all covering
# relations in J(P) for things that are above loc(x).
K = [[loc[x]]]
K0 = [[loc[x]]]
j = 0
while K[j]:
K.append([b for a in K[j] for b in Jup[a]])
while K0[j]:
K0.append([b for a in K0[j] for b in Jup[a]])
j += 1
K = sorted({item for sublist in K for item in sublist})
K = sorted({item for sublist in K0 for item in sublist})
for j in range(len(K)):
i = m + j + 1
Jup[i] = [m + K.index(a) + 1 for a in Jup[K[j]]]
Expand Down
33 changes: 15 additions & 18 deletions src/sage/combinat/posets/posets.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,15 +699,12 @@
if element_labels is not None:
P = P.relabel(element_labels)
return P
else:
if element_labels is None:
return FinitePoset(data, elements=data._elements, category=category, facade=facade)
else:
return FinitePoset(data, elements=element_labels, category=category, facade=facade)
if element_labels is None:
return FinitePoset(data, elements=data._elements, category=category, facade=facade)
return FinitePoset(data, elements=element_labels, category=category, facade=facade)

Check warning on line 704 in src/sage/combinat/posets/posets.py

View check run for this annotation

Codecov / codecov/patch

src/sage/combinat/posets/posets.py#L702-L704

Added lines #L702 - L704 were not covered by tests

# Convert data to a DiGraph
elements = None
D = {}
if data is None: # type 0
D = DiGraph()
elif isinstance(data, DiGraph): # type 4
Expand Down Expand Up @@ -1529,10 +1526,11 @@
sage: P.sorted([], allow_incomparable=False, remove_duplicates=False)
[]
"""
v = [self._element_to_vertex(x) for x in l]
v = (self._element_to_vertex(x) for x in l)
if remove_duplicates:
v = set(v)
o = sorted(v)
o = sorted(set(v))
else:
o = sorted(v)

if not allow_incomparable:
H = self._hasse_diagram
Expand Down Expand Up @@ -2716,10 +2714,9 @@
for y in H.neighbor_out_iterator(xmax):
if exposant == 1:
next_stock.append((xmin, y, y))
else:
if (cov_xmin, y) in short_stock:
if H.is_linear_interval(xmin, y):
next_stock.append((xmin, cov_xmin, y))
elif (cov_xmin, y) in short_stock:
if H.is_linear_interval(xmin, y):
next_stock.append((xmin, cov_xmin, y))
if next_stock:
poly.append(len(next_stock))
stock = next_stock
Expand Down Expand Up @@ -2856,12 +2853,12 @@
closure = self._hasse_diagram.transitive_closure()
for m, n in chain_pairs:
try:
m, n = Integer(m), Integer(n)
ZZm, ZZn = Integer(m), Integer(n)
except TypeError:
raise TypeError(f"{m} and {n} must be integers")
if m < 1 or n < 1:
raise ValueError(f"{m} and {n} must be positive integers")
twochains = digraphs.TransitiveTournament(m) + digraphs.TransitiveTournament(n)
twochains = digraphs.TransitiveTournament(ZZm) + digraphs.TransitiveTournament(ZZn)
if closure.subgraph_search(twochains, induced=True) is not None:
return False
return True
Expand Down Expand Up @@ -5324,9 +5321,9 @@
neigh1 = [z for z in prod_dg.neighbor_iterator(x)
if edge_color(x, z) == i1]
for x0, x1 in product(neigh0, neigh1):
x2 = list(x0)
x2[i1] = x1[i1]
x2 = tuple(x2)
_x2 = list(x0)
_x2[i1] = x1[i1]
x2 = tuple(_x2)
A0 = prod_dg.has_edge(x, x0)
B0 = prod_dg.has_edge(x1, x2)
if A0 != B0:
Expand Down
Loading