From 81a71ae73cc6c60101fb583b87b5ba0085e164bb Mon Sep 17 00:00:00 2001 From: nbruin Date: Wed, 21 Feb 2024 20:20:46 -0800 Subject: [PATCH 1/5] Remove long/int relic in py2, long and int were different types. In py3, only int remains, with long a synonym in cython. --- src/sage/rings/integer_ring.pyx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx index 559de2065e2..f4da4a8c961 100644 --- a/src/sage/rings/integer_ring.pyx +++ b/src/sage/rings/integer_ring.pyx @@ -586,10 +586,8 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: f(-7r) -7 """ - if S is long: + if S is int: return sage.rings.integer.long_to_Z() - elif S is int: - return sage.rings.integer.int_to_Z() elif S is bool: return True elif is_numpy_type(S): From 33e14a90c6a4579bcf60d91e8c1c87b19a53550f Mon Sep 17 00:00:00 2001 From: nbruin Date: Thu, 22 Feb 2024 08:58:33 -0800 Subject: [PATCH 2/5] remove int_to_Z because it's buggy int_to_Z used to work in Py2 on the type "int" there which were integers that fit in a word. In Py3 there is no such type anymore and "int" now is what "long" used to be -- -arbitrary length integers. In Py3 int_to_Z is buggy: sage: itoZ=sage.rings.integer.int_to_Z() sage: itoZ(1000000000000000000000) OverflowError --- src/sage/rings/integer.pyx | 81 -------------------------------------- 1 file changed, 81 deletions(-) diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index aa7d4855bbb..d9f9deede99 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -7389,87 +7389,6 @@ def make_integer(s): return r -cdef class int_to_Z(Morphism): - """ - Morphism from Python ints to Sage integers. - - EXAMPLES:: - - sage: f = ZZ.coerce_map_from(int) - sage: type(f) - - sage: f(5r) - 5 - sage: type(f(5r)) - - sage: 1 + 2r - 3 - sage: type(1 + 2r) - - - This is intended for internal use by the coercion system, - to facilitate fast expressions mixing ints and more complex - Python types. Note that (as with all morphisms) the input - is forcably coerced to the domain ``int`` if it is not - already of the correct type which may have undesirable results:: - - sage: f.domain() - Set of Python objects of class 'int' - sage: f(1/3) - 0 - sage: f(1.7) - 1 - sage: f("10") - 10 - - A pool is used for small integers:: - - sage: f(10) is f(10) - True - sage: f(-2) is f(-2) - True - """ - - def __init__(self): - """ - TESTS:: - - sage: f = ZZ.coerce_map_from(int) - sage: f.parent() - Set of Morphisms from Set of Python objects of class 'int' to Integer Ring in Category of sets - """ - import sage.categories.homset - from sage.sets.pythonclass import Set_PythonType - Morphism.__init__(self, sage.categories.homset.Hom(Set_PythonType(int), integer_ring.ZZ)) - - cpdef Element _call_(self, a) noexcept: - """ - Return a new integer with the same value as ``a``. - - TESTS:: - - sage: f = ZZ.coerce_map_from(int) - sage: f(100r) - 100 - """ - if type(a) is not int: - raise TypeError("must be a Python int object") - - return smallInteger(PyLong_AsLong(a)) - - def _repr_type(self): - """ - TESTS:: - - sage: f = ZZ.coerce_map_from(int) - sage: print(f) - Native morphism: - From: Set of Python objects of class 'int' - To: Integer Ring - """ - return "Native" - - cdef class long_to_Z(Morphism): """ EXAMPLES:: From fa1905c556e570060574f9a6acf98be72c62afed Mon Sep 17 00:00:00 2001 From: nbruin Date: Thu, 22 Feb 2024 09:00:00 -0800 Subject: [PATCH 3/5] remove forward declaration of int_to_Z --- src/sage/rings/integer.pxd | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/sage/rings/integer.pxd b/src/sage/rings/integer.pxd index 2f81c164943..b831f095eb1 100644 --- a/src/sage/rings/integer.pxd +++ b/src/sage/rings/integer.pxd @@ -42,6 +42,3 @@ cdef inline Integer _Integer_from_mpz(mpz_t e) noexcept: cdef Integer z = Integer.__new__(Integer) mpz_set(z.value, e) return z - -cdef class int_to_Z(Morphism): - pass From d8298b98692e249ea0575b6f19351b9e9b79d53d Mon Sep 17 00:00:00 2001 From: nbruin Date: Thu, 22 Feb 2024 10:48:37 -0800 Subject: [PATCH 4/5] rename long_to_Z to int_to_Z --- src/sage/rings/integer.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index d9f9deede99..4b837947047 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -7389,7 +7389,7 @@ def make_integer(s): return r -cdef class long_to_Z(Morphism): +cdef class int_to_Z(Morphism): """ EXAMPLES:: From 18ace4ee14b6402f68b8819d21350130c9054c09 Mon Sep 17 00:00:00 2001 From: nbruin Date: Thu, 22 Feb 2024 10:49:41 -0800 Subject: [PATCH 5/5] adapt call site to int_to_Z --- src/sage/rings/integer_ring.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx index f4da4a8c961..e35559d68d8 100644 --- a/src/sage/rings/integer_ring.pyx +++ b/src/sage/rings/integer_ring.pyx @@ -587,7 +587,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): -7 """ if S is int: - return sage.rings.integer.long_to_Z() + return sage.rings.integer.int_to_Z() elif S is bool: return True elif is_numpy_type(S):