Skip to content

Commit

Permalink
Suggestions by tscrim
Browse files Browse the repository at this point in the history
  • Loading branch information
gmou3 committed Feb 26, 2024
1 parent cbb774b commit 3828d3c
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 78 deletions.
9 changes: 5 additions & 4 deletions src/sage/matroids/basis_exchange_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1237,8 +1237,8 @@ cdef class BasisExchangeMatroid(Matroid):
Return the Whitney numbers of the second kind of the matroid.
The Whitney numbers of the second kind are here encoded as a vector
`(W_0, ..., W_r)`, where `W_i` is the number of flats of rank `i`, and
`r` is the rank of the matroid.
`(W_0, \ldots, W_r)`, where `W_i` is the number of flats of rank `i`,
and `r` is the rank of the matroid.
OUTPUT: a list of integers
Expand Down Expand Up @@ -1949,15 +1949,16 @@ cdef class BasisExchangeMatroid(Matroid):
sage: M._weak_invariant() == N._weak_invariant()
False
"""
from sage.matroids.utilities import cmp_elements_key
if self._weak_invariant_var is None:
if self.full_rank() == 0 or self.full_corank() == 0:
self._weak_invariant_var = 0
self._weak_partition_var = SetSystem(self._E, [self.groundset()])
else:
k = min(self.full_rank() - 1, 2)
fie, f_vec = self._flat_element_inv(k)
self._weak_invariant_var = hash(tuple([tuple([(f, len(fie[f])) for f in sorted(fie, key=str)]), f_vec]))
self._weak_partition_var = SetSystem(self._E, [fie[f] for f in sorted(fie, key=str)])
self._weak_invariant_var = hash(tuple([tuple([(f, len(fie[f])) for f in sorted(fie, key=cmp_elements_key)]), f_vec]))
self._weak_partition_var = SetSystem(self._E, [fie[f] for f in sorted(fie, key=cmp_elements_key)])
return self._weak_invariant_var

cpdef _weak_partition(self) noexcept:
Expand Down
3 changes: 2 additions & 1 deletion src/sage/matroids/circuits_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,9 @@ cdef class CircuitsMatroid(Matroid):
sage: C1 == C2
True
"""
from sage.matroids.utilities import cmp_elements_key
if ordering is None:
ordering = sorted(self.groundset(), key=str)
ordering = sorted(self.groundset(), key=cmp_elements_key)
else:
if frozenset(ordering) != self.groundset():
raise ValueError("not an ordering of the groundset")
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ cdef class Matroid(SageObject):
cpdef _internal(self, B) noexcept
cpdef _external(self, B) noexcept
cpdef tutte_polynomial(self, x=*, y=*) noexcept
cpdef characteristic_polynomial(self, l=*) noexcept
cpdef characteristic_polynomial(self, la=*) noexcept
cpdef flat_cover(self, solver=*, verbose=*, integrality_tolerance=*) noexcept

# misc
Expand Down
Loading

0 comments on commit 3828d3c

Please sign in to comment.