Skip to content

Commit

Permalink
sagemathgh-39405: Resolve error in transversal_matroid.pyx
Browse files Browse the repository at this point in the history
An error appears on some ``Python`` implementations because of a bug in
``transversal_extension``.
The solution is to ensure that the label of `newset` is not `element`.

Reported to me in
sagemath#39155 (comment).

URL: sagemath#39405
Reported by: gmou3
Reviewer(s): Frédéric Chapoton
  • Loading branch information
Release Manager committed Jan 30, 2025
2 parents f51aea1 + ef07593 commit 05b5068
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tarball=configure-VERSION.tar.gz
sha1=86711d4cbef2cd4e7bb4afcde36965e5dea908e0
sha256=9793cf92ebdceb09050a585294de93c242c033745a0012cae1bd301d307a45df
sha1=ae4e553c8b43ea4fd5bb3a178a975a71b256f989
sha256=495e94f3d72b725715f0307b25f781d3c908816a88bf9a891fd3e0e050635b03
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
efc0914cd8d72a9bdfdcca4511b55e290b9b6674
1206533093cda4ddd0f5cbe067ab8a7384892a07
12 changes: 7 additions & 5 deletions src/sage/matroids/transversal_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ cdef class TransversalMatroid(BasisExchangeMatroid):
labels.append(l)
return TransversalMatroid(sets, groundset=self.groundset(), set_labels=labels)

cpdef transversal_extension(self, element=None, newset=False, sets=[]):
cpdef transversal_extension(self, element=None, newset=False, sets=None):
r"""
Return a :class:`TransversalMatroid` extended by an element.
Expand Down Expand Up @@ -751,6 +751,8 @@ cdef class TransversalMatroid(BasisExchangeMatroid):
Transversal matroid of rank 3 on 5 elements, with 3 sets
sage: Ne = N.transversal_extension(element='f', sets=['s2'])
"""
if sets is None:
sets = []
cdef set parsed_sets = set(sets)
if element is None:
element = newlabel(self._groundset)
Expand Down Expand Up @@ -781,17 +783,17 @@ cdef class TransversalMatroid(BasisExchangeMatroid):
else:
new_sets.append(s)

groundset = self._groundset.union([element])
if newset:
if newset is True:
newset = newlabel(self._groundset.union(labels))
newset = newlabel(groundset.union(labels))
new_sets.append([element])
labels = list(labels) # Make a shallow copy since we mutate it
labels.append(newset)

groundset = self._groundset.union([element])
return TransversalMatroid(new_sets, groundset, labels)

def transversal_extensions(self, element=None, sets=[]):
def transversal_extensions(self, element=None, sets=None):
r"""
Return an iterator of extensions based on the transversal presentation.
Expand Down Expand Up @@ -829,7 +831,7 @@ cdef class TransversalMatroid(BasisExchangeMatroid):
raise ValueError("cannot extend by element already in groundset")

labels = self._set_labels_input
if not sets:
if sets is None:
sets = labels
elif not set(sets).issubset(labels):
raise ValueError("sets do not match presentation")
Expand Down

0 comments on commit 05b5068

Please sign in to comment.