Skip to content

Commit 7ecf985

Browse files
author
Release Manager
committed
gh-35455: Faster get_unsafe for NTL GF(p) polynomials ### 📚 Description Unlike similar Zmod(n) polynomials, the GF(p) NTL polynomials would call the IntegerModRing constructor for each get_unsafe call resulting in very slow polynomial evaluation. Benchmarks: ``` p = next_prime(2**80) pol = GF(p)["x"].random_element(80000) # Before # evaluate pol at a random GF(p) element: 260.6ms # evaluate pol at a random GF(p^2) element: 790.1ms # evaluate pol at a random GF(p^5) element: 1155.8ms # After # evaluate pol at a random GF(p) element: 66.8ms # evaluate pol at a random GF(p^2) element: 541.2ms # evaluate pol at a random GF(p^5) element: 889.9ms ``` ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. URL: #35455 Reported by: Rémy Oudompheng Reviewer(s): Marc Mezzarobba, Rémy Oudompheng
2 parents 266e61f + bf927cc commit 7ecf985

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

src/sage/libs/ntl/ntl_ZZ_pX.pyx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,7 @@ cdef class ntl_ZZ_pX():
264264
if i < 0:
265265
r.set_from_int(0)
266266
else:
267-
sig_on()
268267
r.x = ZZ_pX_coeff( self.x, i)
269-
sig_off()
270268
return r
271269

272270
cdef int getitem_as_int(ntl_ZZ_pX self, long i):

src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ cdef class Polynomial_dense_mod_n(Polynomial):
209209
sage: f[:3]
210210
13*x^2 + 10*x + 5
211211
"""
212-
return self._parent._base(self.__poly[n]._sage_())
212+
return self._parent._base((<ntl_ZZ_pX> self.__poly)[n]._integer_())
213213

214214
def _unsafe_mutate(self, n, value):
215215
n = int(n)

0 commit comments

Comments
 (0)