@@ -423,15 +423,18 @@ cpdef bint is_numpy_type(t):
423
423
EXAMPLES::
424
424
425
425
sage: from sage.structure.coerce import is_numpy_type
426
- sage: import numpy # needs numpy
427
- sage: is_numpy_type(numpy.int16) # needs numpy
426
+
427
+ sage: # needs numpy
428
+ sage: import numpy
429
+ sage: is_numpy_type(numpy.int16)
428
430
True
429
- sage: is_numpy_type(numpy.floating) # needs numpy
431
+ sage: is_numpy_type(numpy.floating)
430
432
True
431
- sage: is_numpy_type(numpy.ndarray) # needs numpy
433
+ sage: is_numpy_type(numpy.ndarray)
432
434
True
433
- sage: is_numpy_type(numpy.matrix) # needs numpy
435
+ sage: is_numpy_type(numpy.matrix)
434
436
True
437
+
435
438
sage: is_numpy_type(int)
436
439
False
437
440
sage: is_numpy_type(Integer)
@@ -923,20 +926,23 @@ cdef class CoercionModel:
923
926
cpdef analyse(self , xp, yp, op = mul):
924
927
"""
925
928
Emulate the process of doing arithmetic between xp and yp, returning
926
- a list of steps and the parent that the result will live in. The
927
- ``explain`` function is easier to use, but if one wants access to
929
+ a list of steps and the parent that the result will live in.
930
+
931
+ The :meth:`explain` method is easier to use, but if one wants access to
928
932
the actual morphism and action objects (rather than their string
929
- representations) then this is the function to use.
933
+ representations), then this is the function to use.
930
934
931
935
EXAMPLES::
932
936
933
937
sage: cm = sage.structure.element.get_coercion_model()
934
938
sage: GF7 = GF(7)
935
939
sage: steps, res = cm.analyse(GF7, ZZ)
936
940
sage: steps
937
- ['Coercion on right operand via', Natural morphism:
941
+ ['Coercion on right operand via',
942
+ Natural morphism:
938
943
From: Integer Ring
939
- To: Finite Field of size 7, 'Arithmetic performed after coercions.']
944
+ To: Finite Field of size 7,
945
+ 'Arithmetic performed after coercions.']
940
946
sage: res
941
947
Finite Field of size 7
942
948
sage: f = steps[1]; type(f)
@@ -1016,9 +1022,10 @@ cdef class CoercionModel:
1016
1022
1017
1023
def common_parent (self , *args ):
1018
1024
"""
1019
- Computes a common parent for all the inputs. It's essentially
1020
- an `n`-ary canonical coercion except it can operate on parents
1021
- rather than just elements.
1025
+ Compute a common parent for all the inputs.
1026
+
1027
+ It's essentially an `n`-ary canonical coercion except it can
1028
+ operate on parents rather than just elements.
1022
1029
1023
1030
INPUT:
1024
1031
@@ -1027,7 +1034,7 @@ cdef class CoercionModel:
1027
1034
OUTPUT:
1028
1035
1029
1036
A :class:`Parent` into which each input should coerce, or raises a
1030
- `` TypeError` ` if no such :class:`Parent` can be found.
1037
+ :class:` TypeError` if no such :class:`Parent` can be found.
1031
1038
1032
1039
EXAMPLES::
1033
1040
@@ -1122,23 +1129,25 @@ cdef class CoercionModel:
1122
1129
1123
1130
cpdef bin_op(self , x, y, op):
1124
1131
"""
1125
- Execute the operation op on x and y. It first looks for an action
1126
- corresponding to op, and failing that, it tries to coerces x and y
1127
- into a common parent and calls op on them.
1132
+ Execute the operation ``op`` on `x` and `y`.
1133
+
1134
+ It first looks for an action
1135
+ corresponding to ``op``, and failing that, it tries to coerce `x` and `y`
1136
+ into a common parent and calls ``op`` on them.
1128
1137
1129
- If it cannot make sense of the operation, a TypeError is raised.
1138
+ If it cannot make sense of the operation, a :class:` TypeError` is raised.
1130
1139
1131
1140
INPUT:
1132
1141
1133
- - ``x`` - the left operand
1142
+ - ``x`` - - the left operand
1134
1143
1135
- - ``y`` - the right operand
1144
+ - ``y`` - - the right operand
1136
1145
1137
- - ``op`` - a python function taking 2 arguments
1146
+ - ``op`` -- a python function taking 2 arguments
1138
1147
1139
1148
.. NOTE::
1140
1149
1141
- op is often an arithmetic operation, but need not be so.
1150
+ ``op`` is often an arithmetic operation, but need not be so.
1142
1151
1143
1152
EXAMPLES::
1144
1153
@@ -1268,26 +1277,28 @@ cdef class CoercionModel:
1268
1277
1269
1278
cpdef canonical_coercion(self , x, y):
1270
1279
r """
1271
- Given two elements x and y , with parents S and R respectively,
1272
- find a common parent Z such that there are coercions
1273
- `f: S \m apsto Z` and `g: R \m apsto Z` and return `f( x) , g( y) `
1280
+ Given two elements `x` and `y` , with parents `S` and `R` respectively,
1281
+ find a common parent `Z` such that there are coercions
1282
+ `f: S \t o Z` and `g: R \t o Z` and return `f( x) , g( y) `,
1274
1283
which will have the same parent.
1275
1284
1276
- Raises a type error if no such Z can be found.
1285
+ Raises a type error if no such `Z` can be found.
1277
1286
1278
1287
EXAMPLES::
1279
1288
1280
1289
sage: cm = sage. structure. element. get_coercion_model( )
1281
1290
sage: cm. canonical_coercion( mod( 2, 10) , 17)
1282
1291
( 2, 7)
1283
- sage: x, y = cm. canonical_coercion( 1/2, matrix( ZZ, 2, 2, range( 4))) # needs sage. modules
1284
- sage: x # needs sage. modules
1292
+
1293
+ sage: # needs sage. modules
1294
+ sage: x, y = cm. canonical_coercion( 1/2, matrix( ZZ, 2, 2, range( 4)))
1295
+ sage: x
1285
1296
[1/2 0 ]
1286
1297
[ 0 1/2 ]
1287
- sage: y # needs sage . modules
1298
+ sage: y
1288
1299
[0 1 ]
1289
1300
[2 3 ]
1290
- sage: parent( x) is parent( y) # needs sage . modules
1301
+ sage: parent( x) is parent( y)
1291
1302
True
1292
1303
1293
1304
There is some support for non-Sage datatypes as well::
@@ -1296,7 +1307,6 @@ cdef class CoercionModel:
1296
1307
sage: type( x) , type( y)
1297
1308
( <class 'sage. rings. integer. Integer'>, <class 'sage. rings. integer. Integer'>)
1298
1309
1299
-
1300
1310
sage: x, y = cm. canonical_coercion( int( 5) , complex( 3))
1301
1311
sage: type( x) , type( y)
1302
1312
( <class 'complex'>, <class 'complex'>)
@@ -1411,7 +1421,6 @@ cdef class CoercionModel:
1411
1421
1412
1422
raise TypeError (" no common canonical parent for objects with parents: '%s ' and '%s '" % (xp, yp))
1413
1423
1414
-
1415
1424
cpdef coercion_maps(self , R, S):
1416
1425
r """
1417
1426
Give two parents `R` and `S`, return a pair of coercion maps
@@ -1471,12 +1480,14 @@ cdef class CoercionModel:
1471
1480
False
1472
1481
sage: cm = sage. structure. element. get_coercion_model( )
1473
1482
sage: cm. coercion_maps( V, W)
1474
- ( None, ( map internal to coercion system -- copy before use)
1483
+ ( None,
1484
+ ( map internal to coercion system -- copy before use)
1475
1485
Coercion map:
1476
1486
From: Vector space of dimension 3 over Rational Field
1477
1487
To: Vector space of dimension 3 over Rational Field)
1478
1488
sage: cm. coercion_maps( W, V)
1479
- ( None, ( map internal to coercion system -- copy before use)
1489
+ ( None,
1490
+ ( map internal to coercion system -- copy before use)
1480
1491
Coercion map:
1481
1492
From: Vector space of dimension 3 over Rational Field
1482
1493
To: Vector space of dimension 3 over Rational Field)
@@ -1495,15 +1506,15 @@ cdef class CoercionModel:
1495
1506
sage: # needs sage. libs. pari
1496
1507
sage: import gc
1497
1508
sage: T = type( GF( 2))
1498
- sage: gc. collect( ) # random
1509
+ sage: gc. collect( ) # random
1499
1510
852
1500
1511
sage: N0 = len( list( o for o in gc. get_objects( ) if type( o) is T))
1501
1512
sage: L = [ZZ(1) + GF(p)(1) for p in prime_range(2, 50) ]
1502
1513
sage: N1 = len( list( o for o in gc. get_objects( ) if type( o) is T))
1503
1514
sage: N1 > N0
1504
1515
True
1505
1516
sage: del L
1506
- sage: gc. collect( ) # random
1517
+ sage: gc. collect( ) # random
1507
1518
3939
1508
1519
sage: N2 = len( list( o for o in gc. get_objects( ) if type( o) is T))
1509
1520
sage: N2 - N0
@@ -1561,7 +1572,7 @@ cdef class CoercionModel:
1561
1572
1562
1573
cpdef verify_coercion_maps(self , R, S, homs, bint fix = False ):
1563
1574
"""
1564
- Make sure this is a valid pair of homomorphisms from R and S to a common parent.
1575
+ Make sure this is a valid pair of homomorphisms from `R` and `S` to a common parent.
1565
1576
This function is used to protect the user against buggy parents.
1566
1577
1567
1578
EXAMPLES::
@@ -1631,7 +1642,7 @@ cdef class CoercionModel:
1631
1642
cpdef discover_coercion(self , R, S):
1632
1643
"""
1633
1644
This actually implements the finding of coercion maps as described in
1634
- the `` coercion_maps` ` method.
1645
+ the :meth:` coercion_maps` method.
1635
1646
1636
1647
EXAMPLES::
1637
1648
@@ -1811,15 +1822,15 @@ cdef class CoercionModel:
1811
1822
"""
1812
1823
INPUT:
1813
1824
1814
- - ``R`` - the left Parent (or type)
1815
- - ``S`` - the right Parent (or type)
1816
- - ``op`` - the operand, typically an element of the operator module
1817
- - ``r`` - (optional) element of R
1818
- - ``s`` - (optional) element of S .
1825
+ - ``R`` -- the left :class:` Parent` (or type)
1826
+ - ``S`` -- the right :class:` Parent` (or type)
1827
+ - ``op`` -- the operand, typically an element of the :mod:` operator` module
1828
+ - ``r`` -- (optional) element of `R`
1829
+ - ``s`` -- (optional) element of `S` .
1819
1830
1820
1831
OUTPUT:
1821
1832
1822
- - An action A such that s op r is given by A(s,r).
1833
+ - An action `A` such that `s` ``op`` `r` is given by ` A(s,r)` .
1823
1834
1824
1835
The steps taken are illustrated below.
1825
1836
@@ -1833,13 +1844,14 @@ cdef class CoercionModel:
1833
1844
True
1834
1845
sage: cm = sage.structure.element.get_coercion_model()
1835
1846
1836
- If R or S is a Parent, ask it for an action by/on R ::
1847
+ If `R` or `S` is a :class:` Parent` , ask it for an action by/on `R` ::
1837
1848
1838
1849
sage: cm.discover_action(ZZ, P, operator.mul)
1839
1850
Left scalar multiplication by Integer Ring on
1840
1851
Univariate Polynomial Ring in x over Integer Ring
1841
1852
1842
- If R or S a type, recursively call get_action with the Sage versions of R and/or S::
1853
+ If `R` or `S` a type, recursively call :meth:`get_action`
1854
+ with the Sage versions of `R` and/or `S`::
1843
1855
1844
1856
sage: cm.discover_action(P, int, operator.mul)
1845
1857
Right scalar multiplication by Integer Ring on
@@ -1848,7 +1860,7 @@ cdef class CoercionModel:
1848
1860
From: Set of Python objects of class 'int'
1849
1861
To: Integer Ring
1850
1862
1851
- If op is division, look for action on right by inverse::
1863
+ If ``op`` is division, look for action on `` right`` by inverse::
1852
1864
1853
1865
sage: cm.discover_action(P, ZZ, operator.truediv)
1854
1866
Right inverse action by Rational Field on
0 commit comments