1
+ cimport cython
2
+
1
3
from cpython.list cimport PyList_GET_SIZE
2
4
from flint.flint_base.flint_base cimport flint_poly
3
5
from flint.utils.typecheck cimport typecheck
@@ -18,9 +20,10 @@ from flint.utils.flint_exceptions import DomainError
18
20
cdef dict _nmod_poly_ctx_cache = {}
19
21
20
22
23
+ @cython.no_gc
21
24
cdef class nmod_poly_ctx:
22
25
"""
23
- Context object for creating :class:`~.nmod_poly` initalised
26
+ Context object for creating :class:`~.nmod_poly` initalised
24
27
with modulus :math:`N`.
25
28
26
29
>>> nmod_poly_ctx.new(17)
@@ -170,6 +173,7 @@ cdef class nmod_poly_ctx:
170
173
return nmod_poly(arg, self )
171
174
172
175
176
+ @cython.no_gc
173
177
cdef class nmod_poly(flint_poly):
174
178
"""
175
179
The nmod_poly type represents dense univariate polynomials
@@ -387,7 +391,7 @@ cdef class nmod_poly(flint_poly):
387
391
"""
388
392
if n <= 0 :
389
393
raise ValueError (f" {n = } must be positive" )
390
-
394
+
391
395
if nmod_poly_get_coeff_ui(self .val, 0 ) == 0 :
392
396
raise ZeroDivisionError (f" nmod_poly inverse_series_trunc: leading coefficient is zero" )
393
397
@@ -417,8 +421,8 @@ cdef class nmod_poly(flint_poly):
417
421
if other is NotImplemented :
418
422
raise TypeError (" cannot convert input to nmod_poly" )
419
423
res = self .ctx.new_nmod_poly()
420
- nmod_poly_compose(res.val, self .val, (< nmod_poly> other).val)
421
- return res
424
+ nmod_poly_compose(res.val, self .val, (< nmod_poly> other).val)
425
+ return res
422
426
423
427
def compose_mod (self , other , modulus ):
424
428
r """
@@ -449,8 +453,8 @@ cdef class nmod_poly(flint_poly):
449
453
raise ZeroDivisionError (" cannot reduce modulo zero" )
450
454
451
455
res = self .ctx.new_nmod_poly()
452
- nmod_poly_compose_mod(res.val, self .val, (< nmod_poly> other).val, (< nmod_poly> modulus).val)
453
- return res
456
+ nmod_poly_compose_mod(res.val, self .val, (< nmod_poly> other).val, (< nmod_poly> modulus).val)
457
+ return res
454
458
455
459
def __call__ (self , other ):
456
460
cdef nmod_poly r
@@ -638,7 +642,6 @@ cdef class nmod_poly(flint_poly):
638
642
>>> f = 30* x** 6 + 104* x** 5 + 76* x** 4 + 33* x** 3 + 70* x** 2 + 44* x + 65
639
643
>>> g = 43* x** 6 + 91* x** 5 + 77* x** 4 + 113* x** 3 + 71* x** 2 + 132* x + 60
640
644
>>> mod = x** 4 + 93* x** 3 + 78* x** 2 + 72* x + 149
641
- >>>
642
645
>>> f. pow_mod( 123, mod)
643
646
3* x^ 3 + 25* x^ 2 + 115* x + 161
644
647
>>> f. pow_mod( 2** 64, mod)
@@ -663,7 +666,7 @@ cdef class nmod_poly(flint_poly):
663
666
664
667
# Output polynomial
665
668
res = self .ctx.new_nmod_poly()
666
-
669
+
667
670
# For small exponents, use a simple binary exponentiation method
668
671
if e.bit_length() < 32 :
669
672
nmod_poly_powmod_ui_binexp(
0 commit comments