Skip to content

Commit

Permalink
sagemathgh-36700: use less _element_constructor
Browse files Browse the repository at this point in the history
    
trying to avoid ` _element_constructor` with no final underscore

the only serious change is the one in finite fields morphisms.

### 📝 Checklist

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
    
URL: sagemath#36700
Reported by: Frédéric Chapoton
Reviewer(s): Frédéric Chapoton, Matthias Köppe
  • Loading branch information
Release Manager committed Dec 6, 2023
2 parents 980b9be + f4a7f26 commit 6a49dfa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/sage/combinat/multiset_partition_into_sets_ordered.py
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,7 @@ def _satisfies_constraints(self, x):
.. NOTE::
This test will cause an infinite recursion with
``self._element_constructor()`` if the ``__contains__``
``self._element_constructor_()`` if the ``__contains__``
method in ``OrderedMultisetPartitionsIntoSets_X`` is removed.
TESTS::
Expand Down
29 changes: 17 additions & 12 deletions src/sage/combinat/posets/hasse_cython.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class IncreasingChains(RecursivelyEnumeratedSet_forest):
as given by the lazy attribute ``_leq_storage`` of Hasse diagrams.
- ``element_constructor`` -- used to determine the type of chains,
for example ``list`` or ``tuple``
for example :class:`list` or :class:`tuple`
- ``exclude`` -- list of integers that should not belong to the chains
Expand Down Expand Up @@ -71,7 +71,7 @@ class IncreasingChains(RecursivelyEnumeratedSet_forest):
self._greater_than = positions
self._vertices = list(range(n))

self._element_constructor = element_constructor
self._constructor = element_constructor
self._conversion = conversion
if conversion is not None:
self._from_poset = {elt: i for i, elt in enumerate(conversion)}
Expand All @@ -92,8 +92,8 @@ class IncreasingChains(RecursivelyEnumeratedSet_forest):
sage: from sage.combinat.posets.hasse_cython import IncreasingChains
sage: D = IncreasingChains([{0,1},{1}], list, [])
sage: [x in D for x in D]
[True, True, True, True]
sage: all(x in D for x in D)
True
sage: [2] in D
False
sage: [1,1] in D
Expand All @@ -102,16 +102,22 @@ class IncreasingChains(RecursivelyEnumeratedSet_forest):
sage: P = Poset({'a':['b'],'b':[]})
sage: ['a'] in P.chains()
True
TESTS::
sage: from sage.combinat.posets.hasse_cython import IncreasingChains
sage: D = IncreasingChains([{0,1},{1}], list, [])
sage: all(tuple(x) in D for x in D)
True
"""
cdef int k
cdef Py_ssize_t i, x, y
if not tup:
return True
if self._conversion is not None:
tup = [self._from_poset[elt] for elt in tup]
for i in tup:
if not(0 <= i < self._n):
return False
if any(not(0 <= i < self._n) for i in tup):
return False
y = tup[0]
for k in range(1, len(tup)):
x = y
Expand Down Expand Up @@ -142,8 +148,8 @@ class IncreasingChains(RecursivelyEnumeratedSet_forest):
"""
cdef Py_ssize_t i
if self._conversion is not None:
return self._element_constructor(self._conversion[i] for i in chain)
return self._element_constructor(chain)
return self._constructor(self._conversion[i] for i in chain)
return self._constructor(chain)

def children(self, chain):
"""
Expand All @@ -163,6 +169,5 @@ class IncreasingChains(RecursivelyEnumeratedSet_forest):
cdef Py_ssize_t x, y
if not chain:
return [(x,) for x in self._vertices]
else:
x = chain[-1]
return [chain + (y,) for y in self._greater_than[x] if x != y]
x = chain[-1]
return [chain + (y,) for y in self._greater_than[x] if x != y]
4 changes: 2 additions & 2 deletions src/sage/rings/finite_rings/hom_prime_finite_field.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ from sage.rings.finite_rings.finite_field_base import FiniteField
cdef class SectionFiniteFieldHomomorphism_prime(SectionFiniteFieldHomomorphism_generic):
cpdef Element _call_(self, x) noexcept:
try:
return self._codomain._element_constructor(x)
return self._codomain._element_constructor_(x)
except TypeError:
raise ValueError("%s is not in the image of %s" % (x, self._inverse))

Expand Down Expand Up @@ -89,7 +89,7 @@ cdef class FiniteFieldHomomorphism_prime(FiniteFieldHomomorphism_generic):
sage: a.parent()
Finite Field in t of size 3^5
"""
return self._codomain._element_constructor(x)
return self._codomain._element_constructor_(x)


cdef class FrobeniusEndomorphism_prime(FrobeniusEndomorphism_finite_field):
Expand Down

0 comments on commit 6a49dfa

Please sign in to comment.