Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove long/int relic #37420

Merged
merged 5 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/sage/rings/integer.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
81 changes: 0 additions & 81 deletions src/sage/rings/integer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7390,87 +7390,6 @@ def make_integer(s):


cdef class int_to_Z(Morphism):
"""
Morphism from Python ints to Sage integers.

EXAMPLES::

sage: f = ZZ.coerce_map_from(int)
sage: type(f)
<class 'sage.rings.integer.long_to_Z'>
sage: f(5r)
5
sage: type(f(5r))
<class 'sage.rings.integer.Integer'>
sage: 1 + 2r
3
sage: type(1 + 2r)
<class 'sage.rings.integer.Integer'>

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::

Expand Down
4 changes: 1 addition & 3 deletions src/sage/rings/integer_ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain):
sage: f(-7r)
-7
"""
if S is long:
return sage.rings.integer.long_to_Z()
elif S is int:
if S is int:
return sage.rings.integer.int_to_Z()
elif S is bool:
return True
Expand Down
Loading