From 09151370dfad704a26b8abf623bb95b018651328 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 26 Jun 2020 22:35:11 -0700 Subject: [PATCH] sage.rings.integer_ring.IntegerRing_class._coerce_ZZ: Remove, replaces uses by calls to ZZ_to_mpz --- src/sage/libs/ntl/ntl_ZZ.pyx | 1 - src/sage/libs/ntl/ntl_ZZ_p.pyx | 8 ++++++-- src/sage/rings/integer_ring.pxd | 2 -- src/sage/rings/integer_ring.pyx | 8 -------- src/sage/rings/number_field/number_field_element.pyx | 11 ++++++++--- src/sage/rings/polynomial/polynomial_zz_pex.pyx | 6 +++++- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/sage/libs/ntl/ntl_ZZ.pyx b/src/sage/libs/ntl/ntl_ZZ.pyx index e46f1fa2052..8a21990db1c 100644 --- a/src/sage/libs/ntl/ntl_ZZ.pyx +++ b/src/sage/libs/ntl/ntl_ZZ.pyx @@ -296,7 +296,6 @@ cdef class ntl_ZZ(object): cdef Integer ans = Integer.__new__(Integer) ZZ_to_mpz(ans.value, &self.x) return ans - #return (ZZ_sage)._coerce_ZZ(&self.x) cdef void set_from_int(ntl_ZZ self, int value): r""" diff --git a/src/sage/libs/ntl/ntl_ZZ_p.pyx b/src/sage/libs/ntl/ntl_ZZ_p.pyx index 42d3adf62a9..fb94ac9fab5 100644 --- a/src/sage/libs/ntl/ntl_ZZ_p.pyx +++ b/src/sage/libs/ntl/ntl_ZZ_p.pyx @@ -473,7 +473,9 @@ cdef class ntl_ZZ_p(object): """ self.c.restore_c() cdef ZZ_c rep = ZZ_p_rep(self.x) - return (ZZ_sage)._coerce_ZZ(&rep) + cdef Integer ans = Integer.__new__(Integer) + ZZ_to_mpz(ans.value, &rep) + return ans def _sage_(self): r""" @@ -495,4 +497,6 @@ cdef class ntl_ZZ_p(object): cdef ZZ_c rep self.c.restore_c() rep = ZZ_p_rep(self.x) - return IntegerModRing(self.modulus()._integer_())((ZZ_sage)._coerce_ZZ(&rep)) + cdef Integer ans = Integer.__new__(Integer) + ZZ_to_mpz(ans.value, &rep) + return IntegerModRing(self.modulus()._integer_())(ans) diff --git a/src/sage/rings/integer_ring.pxd b/src/sage/rings/integer_ring.pxd index 17380e1a692..41afccaa514 100644 --- a/src/sage/rings/integer_ring.pxd +++ b/src/sage/rings/integer_ring.pxd @@ -1,9 +1,7 @@ from .ring cimport PrincipalIdealDomain from .integer cimport Integer from sage.libs.gmp.types cimport mpz_t -from sage.libs.ntl.types cimport ZZ_c cdef class IntegerRing_class(PrincipalIdealDomain): - cdef Integer _coerce_ZZ(self, ZZ_c *z) cdef int _randomize_mpz(self, mpz_t value, x, y, distribution) except -1 cdef object _zero diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx index 6cddfa77d73..e5f84fba450 100644 --- a/src/sage/rings/integer_ring.pyx +++ b/src/sage/rings/integer_ring.pyx @@ -68,7 +68,6 @@ from sage.structure.sequence import Sequence from sage.misc.misc_c import prod from sage.misc.randstate cimport randstate, current_randstate, SAGE_RAND_MAX -from sage.libs.ntl.convert cimport ZZ_to_mpz cimport sage.rings.integer as integer cimport sage.rings.rational as rational @@ -525,13 +524,6 @@ cdef class IntegerRing_class(PrincipalIdealDomain): yield -n n += 1 - cdef Integer _coerce_ZZ(self, ZZ_c *z): - cdef Integer i = Integer.__new__(Integer) - sig_on() - ZZ_to_mpz(i.value, z) - sig_off() - return i - cpdef _coerce_map_from_(self, S): r""" ``x`` canonically coerces to the integers `\ZZ` only if ``x`` diff --git a/src/sage/rings/number_field/number_field_element.pyx b/src/sage/rings/number_field/number_field_element.pyx index d3ef1f515bc..acc56d54dd1 100644 --- a/src/sage/rings/number_field/number_field_element.pyx +++ b/src/sage/rings/number_field/number_field_element.pyx @@ -2734,7 +2734,9 @@ cdef class NumberFieldElement(FieldElement): raise TypeError("Unable to coerce %s to a rational"%self) cdef Integer num = Integer.__new__(Integer) ZZX_getitem_as_mpz(num.value, &self.__numerator, 0) - return num / (ZZ)._coerce_ZZ(&self.__denominator) + cdef Integer den = Integer.__new__(Integer) + ZZ_to_mpz(den.value, &self.__denominator) + return num / den def _algebraic_(self, parent): r""" @@ -3129,7 +3131,8 @@ cdef class NumberFieldElement(FieldElement): ZZX_getitem_as_mpz(z, &self.__numerator, i) cdef void _ntl_denom_as_mpz(self, mpz_t z): - cdef Integer denom = (ZZ)._coerce_ZZ(&self.__denominator) + cdef Integer denom = Integer.__new__(Integer) + ZZ_to_mpz(denom.value, &self.__denominator) mpz_set(z, denom.value) def denominator(self): @@ -3147,7 +3150,9 @@ cdef class NumberFieldElement(FieldElement): sage: a.denominator() 15 """ - return (ZZ)._coerce_ZZ(&self.__denominator) + cdef Integer ans = Integer.__new__(Integer) + ZZ_to_mpz(ans.value, &self.__denominator) + return ans def _set_multiplicative_order(self, n): """ diff --git a/src/sage/rings/polynomial/polynomial_zz_pex.pyx b/src/sage/rings/polynomial/polynomial_zz_pex.pyx index 6748946c2e4..e987620d078 100644 --- a/src/sage/rings/polynomial/polynomial_zz_pex.pyx +++ b/src/sage/rings/polynomial/polynomial_zz_pex.pyx @@ -17,6 +17,7 @@ from sage.libs.ntl.ZZ_pX cimport ZZ_pX_deg, ZZ_pX_coeff from sage.libs.ntl.ntl_ZZ_pX cimport ntl_ZZ_pX from sage.libs.ntl.ZZ_p cimport ZZ_p_rep from sage.libs.ntl.ntl_ZZ_pContext cimport ntl_ZZ_pContext_class +from sage.libs.ntl.convert cimport ZZ_to_mpz # We need to define this stuff before including the templating stuff # to make sure the function get_cparent is found since it is used in @@ -46,6 +47,7 @@ cdef inline ZZ_pE_c_to_list(ZZ_pE_c x): cdef ZZ_pX_c c_pX cdef ZZ_p_c c_p cdef ZZ_c c_c + cdef Integer ans c_pX = ZZ_pE_to_ZZ_pX(x) d = ZZ_pX_deg(c_pX) @@ -53,7 +55,9 @@ cdef inline ZZ_pE_c_to_list(ZZ_pE_c x): for 0 <= j <= d: c_p = ZZ_pX_coeff(c_pX, j) c_c = ZZ_p_rep(c_p) - L.append((ZZ)._coerce_ZZ(&c_c)) + ans = Integer.__new__(Integer) + ZZ_to_mpz(ans.value, &c_c) + L.append(ans) return L