Skip to content

Commit

Permalink
src/sage/rings/polynomial: fix cython codegen
Browse files Browse the repository at this point in the history
function pointers to `cpdef`d functions don't work because of
dispatch
  • Loading branch information
Feyorsh committed Mar 22, 2024
1 parent ab1a517 commit 0c96d61
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/hilbert.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ cdef inline list interred(list L) noexcept:
# that appears later in L.
if not L:
return []
L.sort(key=ETuple.unweighted_degree)
L.sort(key=ETuple._unweighted_degree)
cdef size_t i
cdef ETuple m
cdef list result = [<ETuple> PyList_GET_ITEM(L, 0)]
Expand Down
4 changes: 3 additions & 1 deletion src/sage/rings/polynomial/polydict.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ cdef class ETuple:
cdef ETuple _new(self) noexcept
cdef int get_exp(self, size_t i) noexcept

cpdef int unweighted_degree(self) except *
# can't use cpdef because function pointers
cdef int _unweighted_degree(self) except *
def int unweighted_degree(self) except *
cpdef int weighted_degree(self, tuple w) except *
cpdef int unweighted_quotient_degree(self, ETuple other) except *
cpdef int weighted_quotient_degree(self, ETuple other, tuple w) except *
Expand Down
17 changes: 16 additions & 1 deletion src/sage/rings/polynomial/polydict.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,7 @@ cdef class ETuple:

# additional methods

cpdef int unweighted_degree(self) except *:
cdef int _unweighted_degree(self) except *:
r"""
Return the sum of entries.
Expand All @@ -1863,6 +1863,21 @@ cdef class ETuple:
degree += self._data[2 * i + 1]
return degree

def int unweighted_degree(self) except *:
r"""
Return the sum of entries.
EXAMPLES::
sage: from sage.rings.polynomial.polydict import ETuple
sage: ETuple([1, 1, 0, 2, 0]).unweighted_degree()
4
sage: ETuple([-1, 1]).unweighted_degree()
0
"""
return self._unweighted_degree()


@cython.boundscheck(False)
@cython.wraparound(False)
cpdef int weighted_degree(self, tuple w) except *:
Expand Down

0 comments on commit 0c96d61

Please sign in to comment.