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

use less _element_constructor #36700

Merged
merged 3 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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`
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be renamed without deprecation for the old name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is not a named argument, just an argument

Copy link
Contributor

@mkoeppe mkoeppe Nov 11, 2023

Choose a reason for hiding this comment

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

All arguments are named arguments unless you use , /,. Users can do D = IncreasingChains([{0,1},{1}], element_constructor=list, exclude=[]); D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have rename_keyword but only for keywords, not for args. If you insist, I can make an ad-hoc warning, but I would say it's ok not to deprecate. In particular, it's not in the global namespace.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe the name of the parameter can just be left as is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, done


- ``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
Loading