Skip to content

Commit

Permalink
Use except? for _rank (#2)
Browse files Browse the repository at this point in the history
* Add some `except`s

For C-return-type functions that raise exceptions (and their heirs).

* Use `except?` for `_rank`
  • Loading branch information
gmou3 authored Aug 19, 2024
1 parent 31d6a6b commit d943edc
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/sage/matroids/basis_exchange_matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ cdef class BasisExchangeMatroid(Matroid):
cpdef _move_current_basis(self, X, Y)

cpdef frozenset _max_independent(self, frozenset F)
cpdef int _rank(self, frozenset F) except -1
cpdef int _rank(self, frozenset F) except? -1
cpdef frozenset _circuit(self, frozenset F)
cpdef frozenset _fundamental_circuit(self, frozenset B, e)
cpdef frozenset _closure(self, frozenset F)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/basis_exchange_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ cdef class BasisExchangeMatroid(Matroid):
self.__max_independent(self._output, self._input)
return self.__unpack(self._output)

cpdef int _rank(self, frozenset F) except -1:
cpdef int _rank(self, frozenset F) except? -1:
"""
Compute the rank of a subset of the groundset.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/circuit_closures_matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cdef class CircuitClosuresMatroid(Matroid):
cdef dict _circuit_closures # _CC
cdef int _matroid_rank # _R
cpdef frozenset groundset(self)
cpdef int _rank(self, frozenset X) except -1
cpdef int _rank(self, frozenset X) except? -1
cpdef full_rank(self)
cpdef bint _is_independent(self, frozenset F) noexcept
cpdef frozenset _max_independent(self, frozenset F)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/circuit_closures_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ cdef class CircuitClosuresMatroid(Matroid):
"""
return frozenset(self._groundset)

cpdef int _rank(self, frozenset X) except -1:
cpdef int _rank(self, frozenset X) except? -1:
"""
Return the rank of a set ``X``.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/circuits_matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cdef class CircuitsMatroid(Matroid):
cdef list _sorted_C_lens
cdef bint _nsc_defined
cpdef frozenset groundset(self)
cpdef int _rank(self, frozenset X) except -1
cpdef int _rank(self, frozenset X) except? -1
cpdef full_rank(self)
cpdef bint _is_independent(self, frozenset X) noexcept
cpdef frozenset _max_independent(self, frozenset X)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/circuits_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ cdef class CircuitsMatroid(Matroid):
"""
return self._groundset

cpdef int _rank(self, frozenset X) except -1:
cpdef int _rank(self, frozenset X) except? -1:
"""
Return the rank of a set ``X``.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/flats_matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cdef class FlatsMatroid(Matroid):
cdef object _L # lattice of flats
cpdef frozenset groundset(self)

cpdef int _rank(self, frozenset X) except -1
cpdef int _rank(self, frozenset X) except? -1
cpdef frozenset _closure(self, frozenset X)
cpdef bint _is_closed(self, frozenset X) noexcept

Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/flats_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ cdef class FlatsMatroid(Matroid):
"""
return self._groundset

cpdef int _rank(self, frozenset X) except -1:
cpdef int _rank(self, frozenset X) except? -1:
"""
Return the rank of a set ``X``.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/graphic_matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cdef class GraphicMatroid(Matroid):
cdef dict _vertex_map
cdef dict _groundset_edge_map
cpdef frozenset groundset(self)
cpdef int _rank(self, frozenset X) except -1
cpdef int _rank(self, frozenset X) except? -1
cpdef _vertex_stars(self)
cpdef _minor(self, contractions, deletions)
cpdef _has_minor(self, N, bint certificate=*)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/graphic_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ cdef class GraphicMatroid(Matroid):
"""
return self._groundset

cpdef int _rank(self, frozenset X) except -1:
cpdef int _rank(self, frozenset X) except? -1:
"""
Return the rank of a set ``X``.
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 @@ -9,7 +9,7 @@ cdef class Matroid(SageObject):

# virtual methods
cpdef frozenset groundset(self)
cpdef int _rank(self, frozenset X) except -1
cpdef int _rank(self, frozenset X) except? -1

# internal methods, assuming verified input
cpdef frozenset _max_independent(self, frozenset X)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matroids/matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ cdef class Matroid(SageObject):
"""
raise NotImplementedError("subclasses need to implement this")

cpdef int _rank(self, frozenset X) except -1:
cpdef int _rank(self, frozenset X) except? -1:
r"""
Return the rank of a set ``X``.
Expand Down Expand Up @@ -2339,7 +2339,7 @@ cdef class Matroid(SageObject):
TESTS::
sage: def r(X):
....: return -2
....: return -1
sage: M = Matroid(groundset=[0,1,2], rank_function=r)
sage: M.is_valid()
False
Expand Down
6 changes: 3 additions & 3 deletions src/sage/matroids/union_matroid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ cdef class MatroidUnion(Matroid):
cdef list matroids
cdef frozenset _groundset
cpdef frozenset groundset(self)
cpdef int _rank(self, frozenset X) except -1
cpdef int _rank(self, frozenset X) except? -1

cdef class MatroidSum(Matroid):
cdef list summands
cdef frozenset _groundset
cpdef frozenset groundset(self)
cpdef int _rank(self, frozenset X) except -1
cpdef int _rank(self, frozenset X) except? -1

cdef class PartitionMatroid(Matroid):
cdef dict p
cdef frozenset _groundset
cpdef frozenset groundset(self)
cpdef int _rank(self, frozenset X) except -1
cpdef int _rank(self, frozenset X) except? -1
6 changes: 3 additions & 3 deletions src/sage/matroids/union_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ cdef class MatroidUnion(Matroid):
"""
return self._groundset

cpdef int _rank(self, frozenset X) except -1:
cpdef int _rank(self, frozenset X) except? -1:
r"""
Return the rank of a set ``X``.
Expand Down Expand Up @@ -195,7 +195,7 @@ cdef class MatroidSum(Matroid):
"""
return self._groundset

cpdef int _rank(self, frozenset X) except -1:
cpdef int _rank(self, frozenset X) except? -1:
r"""
Return the rank of a set ``X``.
Expand Down Expand Up @@ -290,7 +290,7 @@ cdef class PartitionMatroid(Matroid):
"""
return self._groundset

cpdef int _rank(self, frozenset X) except -1:
cpdef int _rank(self, frozenset X) except? -1:
r"""
Return the rank of a set ``X``.
Expand Down

0 comments on commit d943edc

Please sign in to comment.