Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
sage.rings.integer_ring.IntegerRing_class._coerce_ZZ: Remove, replace…
Browse files Browse the repository at this point in the history
…s uses by calls to ZZ_to_mpz
  • Loading branch information
Matthias Koeppe committed Jul 13, 2020
1 parent 95cf15c commit 0915137
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/sage/libs/ntl/ntl_ZZ.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<IntegerRing_class>ZZ_sage)._coerce_ZZ(&self.x)

cdef void set_from_int(ntl_ZZ self, int value):
r"""
Expand Down
8 changes: 6 additions & 2 deletions src/sage/libs/ntl/ntl_ZZ_p.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,9 @@ cdef class ntl_ZZ_p(object):
"""
self.c.restore_c()
cdef ZZ_c rep = ZZ_p_rep(self.x)
return (<IntegerRing_class>ZZ_sage)._coerce_ZZ(&rep)
cdef Integer ans = Integer.__new__(Integer)
ZZ_to_mpz(ans.value, &rep)
return ans

def _sage_(self):
r"""
Expand All @@ -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_())((<IntegerRing_class>ZZ_sage)._coerce_ZZ(&rep))
cdef Integer ans = Integer.__new__(Integer)
ZZ_to_mpz(ans.value, &rep)
return IntegerModRing(self.modulus()._integer_())(ans)
2 changes: 0 additions & 2 deletions src/sage/rings/integer_ring.pxd
Original file line number Diff line number Diff line change
@@ -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
8 changes: 0 additions & 8 deletions src/sage/rings/integer_ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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``
Expand Down
11 changes: 8 additions & 3 deletions src/sage/rings/number_field/number_field_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 / (<IntegerRing_class>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"""
Expand Down Expand Up @@ -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 = (<IntegerRing_class>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):
Expand All @@ -3147,7 +3150,9 @@ cdef class NumberFieldElement(FieldElement):
sage: a.denominator()
15
"""
return (<IntegerRing_class>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):
"""
Expand Down
6 changes: 5 additions & 1 deletion src/sage/rings/polynomial/polynomial_zz_pex.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,14 +47,17 @@ 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)
if d>=0:
for 0 <= j <= d:
c_p = ZZ_pX_coeff(c_pX, j)
c_c = ZZ_p_rep(c_p)
L.append((<IntegerRing_class>ZZ)._coerce_ZZ(&c_c))
ans = Integer.__new__(Integer)
ZZ_to_mpz(ans.value, &c_c)
L.append(ans)
return L


Expand Down

0 comments on commit 0915137

Please sign in to comment.