Skip to content

Commit ba2cec2

Browse files
committed
Add @cython.no_gc to nmod_poly and nmod_mat
1 parent aaf6942 commit ba2cec2

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

Diff for: src/flint/types/nmod_mat.pyx

+2-1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ cdef class nmod_mat_ctx:
237237
return nmod_mat(*args, self)
238238

239239

240+
@cython.no_gc
240241
cdef class nmod_mat(flint_mat):
241242
"""
242243
The nmod_mat type represents dense matrices over Z/nZ for word-size n (see
@@ -474,7 +475,7 @@ cdef class nmod_mat(flint_mat):
474475
cdef nmod_mat_struct *sv
475476
cdef nmod_mat_struct *tv
476477
cdef mp_limb_t c
477-
sv = &(<nmod_mat>s).val[0]
478+
sv = &s.val[0]
478479
u = s.ctx.any_as_nmod_mat(t)
479480
if u is NotImplemented:
480481
if s.ctx.any_as_nmod(&c, t):

Diff for: src/flint/types/nmod_poly.pyx

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cimport cython
2+
13
from cpython.list cimport PyList_GET_SIZE
24
from flint.flint_base.flint_base cimport flint_poly
35
from flint.utils.typecheck cimport typecheck
@@ -18,9 +20,10 @@ from flint.utils.flint_exceptions import DomainError
1820
cdef dict _nmod_poly_ctx_cache = {}
1921

2022

23+
@cython.no_gc
2124
cdef class nmod_poly_ctx:
2225
"""
23-
Context object for creating :class:`~.nmod_poly` initalised
26+
Context object for creating :class:`~.nmod_poly` initalised
2427
with modulus :math:`N`.
2528
2629
>>> nmod_poly_ctx.new(17)
@@ -170,6 +173,7 @@ cdef class nmod_poly_ctx:
170173
return nmod_poly(arg, self)
171174

172175

176+
@cython.no_gc
173177
cdef class nmod_poly(flint_poly):
174178
"""
175179
The nmod_poly type represents dense univariate polynomials
@@ -387,7 +391,7 @@ cdef class nmod_poly(flint_poly):
387391
"""
388392
if n <= 0:
389393
raise ValueError(f"{n = } must be positive")
390-
394+
391395
if nmod_poly_get_coeff_ui(self.val, 0) == 0:
392396
raise ZeroDivisionError(f"nmod_poly inverse_series_trunc: leading coefficient is zero")
393397

@@ -417,8 +421,8 @@ cdef class nmod_poly(flint_poly):
417421
if other is NotImplemented:
418422
raise TypeError("cannot convert input to nmod_poly")
419423
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
422426

423427
def compose_mod(self, other, modulus):
424428
r"""
@@ -449,8 +453,8 @@ cdef class nmod_poly(flint_poly):
449453
raise ZeroDivisionError("cannot reduce modulo zero")
450454

451455
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
454458

455459
def __call__(self, other):
456460
cdef nmod_poly r
@@ -638,7 +642,6 @@ cdef class nmod_poly(flint_poly):
638642
>>> f = 30*x**6 + 104*x**5 + 76*x**4 + 33*x**3 + 70*x**2 + 44*x + 65
639643
>>> g = 43*x**6 + 91*x**5 + 77*x**4 + 113*x**3 + 71*x**2 + 132*x + 60
640644
>>> mod = x**4 + 93*x**3 + 78*x**2 + 72*x + 149
641-
>>>
642645
>>> f.pow_mod(123, mod)
643646
3*x^3 + 25*x^2 + 115*x + 161
644647
>>> f.pow_mod(2**64, mod)
@@ -663,7 +666,7 @@ cdef class nmod_poly(flint_poly):
663666

664667
# Output polynomial
665668
res = self.ctx.new_nmod_poly()
666-
669+
667670
# For small exponents, use a simple binary exponentiation method
668671
if e.bit_length() < 32:
669672
nmod_poly_powmod_ui_binexp(

0 commit comments

Comments
 (0)