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

Commit d7eb179

Browse files
committed
Remove RingHomomorphism_coercion
In the places where this was still used, _call_ was overriden, so the only thing that we need to take care of are the comparison operators. Running the TestSuite for all of them should make sure that we catch all the equalities that need to be replaced (otherwise pickling fails.)
1 parent 2043ff3 commit d7eb179

13 files changed

+133
-167
lines changed

src/sage/rings/fraction_field_FpT.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from sage.libs.flint.types cimport nmod_poly_t
22

3-
from sage.rings.morphism cimport RingHomomorphism_coercion
3+
from sage.rings.morphism cimport RingHomomorphism
44
from sage.categories.morphism cimport Morphism
55
from sage.structure.element cimport Element, ModuleElement, RingElement
66
from sage.categories.map cimport Section

src/sage/rings/fraction_field_FpT.pyx

+37-12
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ cdef class FpT_iter:
996996
self.cur = next_
997997
return self.cur
998998

999-
cdef class Polyring_FpT_coerce(RingHomomorphism_coercion):
999+
cdef class Polyring_FpT_coerce(RingHomomorphism):
10001000
"""
10011001
This class represents the coercion map from GF(p)[t] to GF(p)(t)
10021002
@@ -1010,6 +1010,11 @@ cdef class Polyring_FpT_coerce(RingHomomorphism_coercion):
10101010
To: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 5
10111011
sage: type(f)
10121012
<type 'sage.rings.fraction_field_FpT.Polyring_FpT_coerce'>
1013+
1014+
TESTS::
1015+
1016+
TestSuite(f).run()
1017+
10131018
"""
10141019
cdef long p
10151020

@@ -1024,7 +1029,7 @@ cdef class Polyring_FpT_coerce(RingHomomorphism_coercion):
10241029
sage: R.<t> = GF(next_prime(2000))[]
10251030
sage: K = R.fraction_field() # indirect doctest
10261031
"""
1027-
RingHomomorphism_coercion.__init__(self, R.ring_of_integers().Hom(R), check=False)
1032+
RingHomomorphism.__init__(self, R.ring_of_integers().Hom(R))
10281033
self.p = R.base_ring().characteristic()
10291034

10301035
cdef dict _extra_slots(self, dict _slots):
@@ -1040,7 +1045,7 @@ cdef class Polyring_FpT_coerce(RingHomomorphism_coercion):
10401045
t^2 + 1
10411046
"""
10421047
_slots['p'] = self.p
1043-
return RingHomomorphism_coercion._extra_slots(self, _slots)
1048+
return RingHomomorphism._extra_slots(self, _slots)
10441049

10451050
cdef _update_slots(self, dict _slots):
10461051
"""
@@ -1055,7 +1060,7 @@ cdef class Polyring_FpT_coerce(RingHomomorphism_coercion):
10551060
t^2 + 1
10561061
"""
10571062
self.p = _slots['p']
1058-
RingHomomorphism_coercion._update_slots(self, _slots)
1063+
RingHomomorphism._update_slots(self, _slots)
10591064

10601065
cpdef Element _call_(self, _x):
10611066
"""
@@ -1193,6 +1198,11 @@ cdef class FpT_Polyring_section(Section):
11931198
To: Univariate Polynomial Ring in t over Finite Field of size 5
11941199
sage: type(f)
11951200
<type 'sage.rings.fraction_field_FpT.FpT_Polyring_section'>
1201+
1202+
TESTS::
1203+
1204+
sage: TestSuite(f).run()
1205+
11961206
"""
11971207
cdef long p
11981208

@@ -1290,7 +1300,7 @@ cdef class FpT_Polyring_section(Section):
12901300
ans._cparent = get_cparent(ans._parent)
12911301
return ans
12921302

1293-
cdef class Fp_FpT_coerce(RingHomomorphism_coercion):
1303+
cdef class Fp_FpT_coerce(RingHomomorphism):
12941304
"""
12951305
This class represents the coercion map from GF(p) to GF(p)(t)
12961306
@@ -1304,6 +1314,11 @@ cdef class Fp_FpT_coerce(RingHomomorphism_coercion):
13041314
To: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 5
13051315
sage: type(f)
13061316
<type 'sage.rings.fraction_field_FpT.Fp_FpT_coerce'>
1317+
1318+
TESTS::
1319+
1320+
sage: TestSuite(f).run()
1321+
13071322
"""
13081323
cdef long p
13091324

@@ -1318,7 +1333,7 @@ cdef class Fp_FpT_coerce(RingHomomorphism_coercion):
13181333
sage: R.<t> = GF(next_prime(3000))[]
13191334
sage: K = R.fraction_field() # indirect doctest
13201335
"""
1321-
RingHomomorphism_coercion.__init__(self, R.base_ring().Hom(R), check=False)
1336+
RingHomomorphism.__init__(self, R.base_ring().Hom(R))
13221337
self.p = R.base_ring().characteristic()
13231338

13241339
cdef dict _extra_slots(self, dict _slots):
@@ -1337,7 +1352,7 @@ cdef class Fp_FpT_coerce(RingHomomorphism_coercion):
13371352
True
13381353
"""
13391354
_slots['p'] = self.p
1340-
return RingHomomorphism_coercion._extra_slots(self, _slots)
1355+
return RingHomomorphism._extra_slots(self, _slots)
13411356

13421357
cdef _update_slots(self, dict _slots):
13431358
"""
@@ -1355,7 +1370,7 @@ cdef class Fp_FpT_coerce(RingHomomorphism_coercion):
13551370
True
13561371
"""
13571372
self.p = _slots['p']
1358-
RingHomomorphism_coercion._update_slots(self, _slots)
1373+
RingHomomorphism._update_slots(self, _slots)
13591374

13601375
cpdef Element _call_(self, _x):
13611376
"""
@@ -1471,6 +1486,11 @@ cdef class FpT_Fp_section(Section):
14711486
To: Finite Field of size 5
14721487
sage: type(f)
14731488
<type 'sage.rings.fraction_field_FpT.FpT_Fp_section'>
1489+
1490+
TESTS::
1491+
1492+
sage: TestSuite(f).run()
1493+
14741494
"""
14751495
cdef long p
14761496

@@ -1587,7 +1607,7 @@ cdef class FpT_Fp_section(Section):
15871607
ans.ivalue = nmod_poly_get_coeff_ui(x._numer, 0)
15881608
return ans
15891609

1590-
cdef class ZZ_FpT_coerce(RingHomomorphism_coercion):
1610+
cdef class ZZ_FpT_coerce(RingHomomorphism):
15911611
"""
15921612
This class represents the coercion map from ZZ to GF(p)(t)
15931613
@@ -1601,6 +1621,11 @@ cdef class ZZ_FpT_coerce(RingHomomorphism_coercion):
16011621
To: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 17
16021622
sage: type(f)
16031623
<type 'sage.rings.fraction_field_FpT.ZZ_FpT_coerce'>
1624+
1625+
TESTS::
1626+
1627+
sage: TestSuite(f).run()
1628+
16041629
"""
16051630
cdef long p
16061631

@@ -1615,7 +1640,7 @@ cdef class ZZ_FpT_coerce(RingHomomorphism_coercion):
16151640
sage: R.<t> = GF(next_prime(3000))[]
16161641
sage: K = R.fraction_field() # indirect doctest
16171642
"""
1618-
RingHomomorphism_coercion.__init__(self, ZZ.Hom(R), check=False)
1643+
RingHomomorphism.__init__(self, ZZ.Hom(R))
16191644
self.p = R.base_ring().characteristic()
16201645

16211646
cdef dict _extra_slots(self, dict _slots):
@@ -1636,7 +1661,7 @@ cdef class ZZ_FpT_coerce(RingHomomorphism_coercion):
16361661
True
16371662
"""
16381663
_slots['p'] = self.p
1639-
return RingHomomorphism_coercion._extra_slots(self, _slots)
1664+
return RingHomomorphism._extra_slots(self, _slots)
16401665

16411666
cdef _update_slots(self, dict _slots):
16421667
"""
@@ -1656,7 +1681,7 @@ cdef class ZZ_FpT_coerce(RingHomomorphism_coercion):
16561681
True
16571682
"""
16581683
self.p = _slots['p']
1659-
RingHomomorphism_coercion._update_slots(self, _slots)
1684+
RingHomomorphism._update_slots(self, _slots)
16601685

16611686
cpdef Element _call_(self, _x):
16621687
"""

src/sage/rings/morphism.pxd

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ cdef class RingMap_lift(RingMap):
1717
cdef class RingHomomorphism(RingMap):
1818
cdef RingMap _lift
1919

20-
cdef class RingHomomorphism_coercion(RingHomomorphism):
21-
pass
22-
2320
cdef class RingHomomorphism_im_gens(RingHomomorphism):
2421
cdef __im_gens
2522

src/sage/rings/morphism.pyx

-101
Original file line numberDiff line numberDiff line change
@@ -901,107 +901,6 @@ cdef class RingHomomorphism(RingMap):
901901
return self._lift
902902
return self._lift(x)
903903

904-
cdef class RingHomomorphism_coercion(RingHomomorphism):
905-
def __init__(self, parent, check = True):
906-
"""
907-
Initialize ``self``.
908-
909-
INPUT:
910-
911-
- ``parent`` -- ring homset
912-
913-
- ``check`` -- bool (default: ``True``)
914-
915-
EXAMPLES::
916-
917-
sage: f = ZZ.hom(QQ); f # indirect doctest
918-
Natural morphism:
919-
From: Integer Ring
920-
To: Rational Field
921-
922-
sage: f == loads(dumps(f))
923-
True
924-
"""
925-
RingHomomorphism.__init__(self, parent)
926-
# putting in check allows us to define subclasses of RingHomomorphism_coercion that implement _coerce_map_from
927-
if check and not self.codomain().has_coerce_map_from(self.domain()):
928-
raise TypeError("Natural coercion morphism from %s to %s not defined."%(self.domain(), self.codomain()))
929-
930-
def _repr_type(self):
931-
"""
932-
Used internally when printing this.
933-
934-
EXAMPLES::
935-
936-
sage: f = ZZ.hom(QQ)
937-
sage: type(f)
938-
<type 'sage.rings.rational.Z_to_Q'>
939-
sage: f._repr_type()
940-
'Natural'
941-
"""
942-
return "Ring Coercion"
943-
944-
def __richcmp__(self, other, int op):
945-
"""
946-
Compare a ring coercion morphism ``self`` to ``other``.
947-
948-
Ring coercion morphisms never compare equal to any other data type. If
949-
other is a ring coercion morphism, the parents of ``self`` and
950-
``other`` are compared.
951-
952-
EXAMPLES::
953-
954-
sage: f = ZZ.hom(QQ)
955-
sage: g = ZZ.hom(ZZ)
956-
sage: f == g
957-
False
958-
959-
sage: h = Zmod(6).lift()
960-
sage: f == h
961-
False
962-
"""
963-
if op not in [Py_EQ, Py_NE]:
964-
return NotImplemented
965-
966-
if not isinstance(other, RingHomomorphism_coercion):
967-
return (op == Py_NE)
968-
969-
# Since they are coercion morphisms they are determined by
970-
# their parents, i.e., by the domain and codomain, so we just
971-
# compare those.
972-
return richcmp(self.parent(), other.parent(), op)
973-
974-
def __hash__(self):
975-
"""
976-
Return the hash of this morphism.
977-
978-
TESTS::
979-
980-
sage: f = ZZ.hom(QQ)
981-
sage: type(f)
982-
<type 'sage.rings.rational.Z_to_Q'>
983-
sage: hash(f) == hash(f)
984-
True
985-
sage: {f: 1}[f]
986-
1
987-
"""
988-
return hash((self.domain(), self.codomain()))
989-
990-
cpdef Element _call_(self, x):
991-
"""
992-
Evaluate this coercion morphism at ``x``.
993-
994-
EXAMPLES::
995-
996-
sage: f = ZZ.hom(QQ); type(f)
997-
<type 'sage.rings.rational.Z_to_Q'>
998-
sage: f(2) == 2
999-
True
1000-
sage: type(f(2)) # indirect doctest
1001-
<type 'sage.rings.rational.Rational'>
1002-
"""
1003-
return self.codomain().coerce(x)
1004-
1005904
import sage.structure.all
1006905

1007906
cdef class RingHomomorphism_im_gens(RingHomomorphism):

src/sage/rings/padics/CA_template.pxi

+18-8
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ cdef class CAElement(pAdicTemplateElement):
10291029
"""
10301030
return chash(self.value, 0, self.absprec, self.prime_pow)
10311031

1032-
cdef class pAdicCoercion_ZZ_CA(RingHomomorphism_coercion):
1032+
cdef class pAdicCoercion_ZZ_CA(RingHomomorphism):
10331033
"""
10341034
The canonical inclusion from the ring of integers to a capped absolute
10351035
ring.
@@ -1040,6 +1040,11 @@ cdef class pAdicCoercion_ZZ_CA(RingHomomorphism_coercion):
10401040
Ring Coercion morphism:
10411041
From: Integer Ring
10421042
To: 5-adic Ring with capped absolute precision 20
1043+
1044+
TESTS::
1045+
1046+
sage: TestSuite(f).run()
1047+
10431048
"""
10441049
def __init__(self, R):
10451050
"""
@@ -1050,7 +1055,7 @@ cdef class pAdicCoercion_ZZ_CA(RingHomomorphism_coercion):
10501055
sage: f = ZpCA(5).coerce_map_from(ZZ); type(f)
10511056
<type 'sage.rings.padics.padic_capped_absolute_element.pAdicCoercion_ZZ_CA'>
10521057
"""
1053-
RingHomomorphism_coercion.__init__(self, ZZ.Hom(R), check=False)
1058+
RingHomomorphism.__init__(self, ZZ.Hom(R))
10541059
self._zero = R._element_constructor(R, 0)
10551060
self._section = pAdicConvert_CA_ZZ(R)
10561061

@@ -1071,7 +1076,7 @@ cdef class pAdicCoercion_ZZ_CA(RingHomomorphism_coercion):
10711076
"""
10721077
_slots['_zero'] = self._zero
10731078
_slots['_section'] = self._section
1074-
return RingHomomorphism_coercion._extra_slots(self, _slots)
1079+
return RingHomomorphism._extra_slots(self, _slots)
10751080

10761081
cdef _update_slots(self, dict _slots):
10771082
"""
@@ -1090,7 +1095,7 @@ cdef class pAdicCoercion_ZZ_CA(RingHomomorphism_coercion):
10901095
"""
10911096
self._zero = _slots['_zero']
10921097
self._section = _slots['_section']
1093-
RingHomomorphism_coercion._update_slots(self, _slots)
1098+
RingHomomorphism._update_slots(self, _slots)
10941099

10951100
cpdef Element _call_(self, x):
10961101
"""
@@ -1346,7 +1351,7 @@ cdef class pAdicConvert_QQ_CA(Morphism):
13461351
cconv_mpq_t(ans.value, (<Rational>x).value, ans.absprec, True, self._zero.prime_pow)
13471352
return ans
13481353

1349-
cdef class pAdicCoercion_CA_frac_field(RingHomomorphism_coercion):
1354+
cdef class pAdicCoercion_CA_frac_field(RingHomomorphism):
13501355
"""
13511356
The canonical inclusion of Zq into its fraction field.
13521357
@@ -1358,6 +1363,11 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism_coercion):
13581363
Ring Coercion morphism:
13591364
From: Unramified Extension of 3-adic Ring with capped absolute precision 20 in a defined by (1 + O(3^20))*x^3 + (O(3^20))*x^2 + (2 + O(3^20))*x + (1 + O(3^20))
13601365
To: Unramified Extension of 3-adic Field with capped relative precision 20 in a defined by (1 + O(3^20))*x^3 + (O(3^20))*x^2 + (2 + O(3^20))*x + (1 + O(3^20))
1366+
1367+
TESTS::
1368+
1369+
sage: TestSuite(f).run()
1370+
13611371
"""
13621372
def __init__(self, R, K):
13631373
"""
@@ -1370,7 +1380,7 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism_coercion):
13701380
sage: f = K.coerce_map_from(R); type(f)
13711381
<type 'sage.rings.padics.qadic_flint_CA.pAdicCoercion_CA_frac_field'>
13721382
"""
1373-
RingHomomorphism_coercion.__init__(self, R.Hom(K), check=False)
1383+
RingHomomorphism.__init__(self, R.Hom(K))
13741384
self._zero = K(0)
13751385
self._section = pAdicConvert_CA_frac_field(K, R)
13761386

@@ -1485,7 +1495,7 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism_coercion):
14851495
"""
14861496
_slots['_zero'] = self._zero
14871497
_slots['_section'] = self._section
1488-
return RingHomomorphism_coercion._extra_slots(self, _slots)
1498+
return RingHomomorphism._extra_slots(self, _slots)
14891499

14901500
cdef _update_slots(self, dict _slots):
14911501
"""
@@ -1513,7 +1523,7 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism_coercion):
15131523
"""
15141524
self._zero = _slots['_zero']
15151525
self._section = _slots['_section']
1516-
RingHomomorphism_coercion._update_slots(self, _slots)
1526+
RingHomomorphism._update_slots(self, _slots)
15171527

15181528
def is_injective(self):
15191529
r"""

0 commit comments

Comments
 (0)