@@ -96,21 +96,22 @@ cdef class Matrix(Matrix0):
96
96
97
97
EXAMPLES::
98
98
99
+ sage: # needs sage.libs.gap
99
100
sage: A = MatrixSpace(QQ,3,3)([0,1,2,3,4,5,6,7,8])
100
- sage: g = gap(A) # indirect doctest # needs sage.libs.gap
101
- sage: g # needs sage.libs.gap
101
+ sage: g = gap(A) # indirect doctest
102
+ sage: g
102
103
[ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ]
103
- sage: g.CharacteristicPolynomial() # needs sage.libs.gap
104
+ sage: g.CharacteristicPolynomial()
104
105
x_1^3-12*x_1^2-18*x_1
105
- sage: A.characteristic_polynomial() # needs sage.libs.gap
106
+ sage: A.characteristic_polynomial()
106
107
x^3 - 12*x^2 - 18*x
107
- sage: matrix(QQ, g) == A # needs sage.libs.gap
108
+ sage: matrix(QQ, g) == A
108
109
True
109
110
110
111
Particularly difficult is the case of matrices over cyclotomic
111
112
fields and general number fields. See :trac:`5618` and :trac:`8909`::
112
113
113
- sage: # needs sage.rings.number_field
114
+ sage: # needs sage.libs.gap sage. rings.number_field
114
115
sage: K.<zeta> = CyclotomicField(8)
115
116
sage: A = MatrixSpace(K, 2, 2)([0, 1+zeta, 2*zeta, 3])
116
117
sage: g = gap(A); g
@@ -120,7 +121,7 @@ cdef class Matrix(Matrix0):
120
121
sage: g.IsMatrix()
121
122
true
122
123
123
- sage: # needs sage.rings.number_field
124
+ sage: # needs sage.libs.gap sage. rings.number_field
124
125
sage: x = polygen(ZZ, 'x')
125
126
sage: L.<tau> = NumberField(x^3 - 2)
126
127
sage: A = MatrixSpace(L, 2, 2)([0, 1+tau, 2*tau, 3])
@@ -157,7 +158,7 @@ cdef class Matrix(Matrix0):
157
158
158
159
sage: libgap(identity_matrix(ZZ, 2)) # needs sage.libs.gap
159
160
[ [ 1, 0 ], [ 0, 1 ] ]
160
- sage: libgap(matrix(GF(3), 2, 2, [4,5,6,7])) # needs sage.libs.gap sage.rings.finite_rings
161
+ sage: libgap(matrix(GF(3), 2, 2, [4,5,6,7])) # needs sage.libs.gap
161
162
[ [ Z(3)^0, Z(3) ], [ 0*Z(3), Z(3)^0 ] ]
162
163
"""
163
164
from sage.libs.gap.libgap import libgap
@@ -301,26 +302,28 @@ cdef class Matrix(Matrix0):
301
302
302
303
We first coerce a square matrix. ::
303
304
305
+ sage: # optional - magma
304
306
sage: A = MatrixSpace( QQ,3) ( [1,2,3,4/3,5/3,6/4,7,8,9 ])
305
- sage: B = magma( A) ; B # ( indirect doctest) optional - magma
307
+ sage: B = magma( A) ; B # indirect doctest
306
308
[ 1 2 3 ]
307
309
[4/3 5/3 3/2 ]
308
310
[ 7 8 9 ]
309
- sage: B. Type( ) # optional - magma
311
+ sage: B. Type( )
310
312
AlgMatElt
311
- sage: B. Parent( ) # optional - magma
313
+ sage: B. Parent( )
312
314
Full Matrix Algebra of degree 3 over Rational Field
313
315
314
316
We coerce a non-square matrix over
315
317
`\Z Z/8\Z Z`. ::
316
318
319
+ sage: # optional - magma
317
320
sage: A = MatrixSpace( Integers( 8) ,2,3) ( [-1,2,3,4,4,-2 ])
318
- sage: B = magma( A) ; B # optional - magma
321
+ sage: B = magma( A) ; B
319
322
[7 2 3 ]
320
323
[4 4 6 ]
321
- sage: B. Type( ) # optional - magma
324
+ sage: B. Type( )
322
325
ModMatRngElt
323
- sage: B. Parent( ) # optional - magma
326
+ sage: B. Parent( )
324
327
Full RMatrixSpace of 2 by 3 matrices over IntegerRing( 8)
325
328
326
329
sage: R. <x,y> = QQ[]
@@ -338,17 +341,17 @@ cdef class Matrix(Matrix0):
338
341
We coerce a matrix over a cyclotomic field, where the generator
339
342
must be named during the coercion. ::
340
343
341
- sage: K = CyclotomicField ( 9 ) ; z = K . 0 # needs sage. rings. number_field
342
- sage: M = matrix ( K, 3, 3, [ 0,1,3,z,z**4,z-1,z**17,1,0 ] ) # needs sage . rings . number_field
343
- sage: M # needs sage . rings . number_field
344
+ sage: # optional - magma, needs sage. rings. number_field
345
+ sage: K = CyclotomicField ( 9 ) ; z = K . 0
346
+ sage: M = matrix ( K, 3, 3, [ 0,1,3,z,z**4,z-1,z**17,1,0 ] ) ; M
344
347
[ 0 1 3 ]
345
348
[ zeta9 zeta9^4 zeta9 - 1 ]
346
349
[-zeta9^5 - zeta9^2 1 0 ]
347
- sage: magma( M) # optional - magma
350
+ sage: magma( M)
348
351
[ 0 1 3 ]
349
352
[ zeta9 zeta9^4 zeta9 - 1 ]
350
353
[-zeta9^5 - zeta9^2 1 0 ]
351
- sage: magma( M** 2) == magma( M) ** 2 # optional - magma
354
+ sage: magma( M** 2) == magma( M) ** 2
352
355
True
353
356
354
357
One sparse matrix::
@@ -438,15 +441,15 @@ cdef class Matrix(Matrix0):
438
441
EXAMPLES::
439
442
440
443
sage: m = matrix(ZZ, [[1,2],[3,4]])
441
- sage: macaulay2(m) #optional - macaulay2 (indirect doctest)
444
+ sage: macaulay2(m) # indirect doctest # optional - macaulay2
442
445
| 1 2 |
443
446
| 3 4 |
444
447
445
448
::
446
449
447
450
sage: R.<x,y> = QQ[]
448
451
sage: m = matrix([[x,y],[1+x,1+y]])
449
- sage: macaulay2(m) # optional - macaulay2
452
+ sage: macaulay2(m) # optional - macaulay2
450
453
| x y |
451
454
| x+1 y+1 |
452
455
@@ -462,9 +465,9 @@ cdef class Matrix(Matrix0):
462
465
Check that degenerate matrix dimensions are handled correctly
463
466
(:trac:`28591`)::
464
467
465
- sage: macaulay2(matrix(QQ, 2, 0)).numrows() # optional - macaulay2
468
+ sage: macaulay2(matrix(QQ, 2, 0)).numrows() # optional - macaulay2
466
469
2
467
- sage: macaulay2(matrix(QQ, 0, 2)).numcols() # optional - macaulay2
470
+ sage: macaulay2(matrix(QQ, 0, 2)).numcols() # optional - macaulay2
468
471
2
469
472
"""
470
473
if macaulay2 is None :
@@ -516,7 +519,7 @@ cdef class Matrix(Matrix0):
516
519
[1 2 3]
517
520
[4 5 6]
518
521
[7 8 9]
519
- sage: b = scilab(a); b # optional - scilab (indirect doctest)
522
+ sage: b = scilab(a); b # indirect doctest # optional - scilab
520
523
1. 2. 3.
521
524
4. 5. 6.
522
525
7. 8. 9.
@@ -577,14 +580,15 @@ cdef class Matrix(Matrix0):
577
580
578
581
Symbolic matrices are supported::
579
582
580
- sage: M = matrix( [[sin(x), cos(x) ], [-cos(x), sin(x) ]]) ; M # needs sage. symbolic
583
+ sage: # needs sympy sage. symbolic
584
+ sage: M = matrix( [[sin(x), cos(x) ], [-cos(x), sin(x) ]]) ; M
581
585
[ sin(x) cos(x) ]
582
586
[-cos(x) sin(x) ]
583
- sage: sM = M. _sympy_( ) ; sM # needs sympy sage . symbolic
587
+ sage: sM = M. _sympy_( ) ; sM
584
588
Matrix( [
585
589
[ sin(x), cos(x) ],
586
590
[-cos(x), sin(x) ]])
587
- sage: sM. subs( x, pi/4) # needs sympy sage . symbolic
591
+ sage: sM. subs( x, pi/4)
588
592
Matrix( [
589
593
[ sqrt(2)/2, sqrt(2)/2 ],
590
594
[-sqrt(2)/2, sqrt(2)/2 ]])
@@ -680,20 +684,21 @@ cdef class Matrix(Matrix0):
680
684
681
685
EXAMPLES::
682
686
687
+ sage: # needs numpy
683
688
sage: a = matrix(3, range(12))
684
- sage: a.numpy() # needs numpy
689
+ sage: a.numpy()
685
690
array([[ 0, 1, 2, 3],
686
691
[ 4, 5, 6, 7],
687
692
[ 8, 9, 10, 11]])
688
- sage: a.numpy('f') # needs numpy
693
+ sage: a.numpy('f')
689
694
array([[ 0., 1., 2., 3.],
690
695
[ 4., 5., 6., 7.],
691
696
[ 8., 9., 10., 11.]], dtype=float32)
692
- sage: a.numpy('d') # needs numpy
697
+ sage: a.numpy('d')
693
698
array([[ 0., 1., 2., 3.],
694
699
[ 4., 5., 6., 7.],
695
700
[ 8., 9., 10., 11.]])
696
- sage: a.numpy('B') # needs numpy
701
+ sage: a.numpy('B')
697
702
array([[ 0, 1, 2, 3],
698
703
[ 4, 5, 6, 7],
699
704
[ 8, 9, 10, 11]], dtype=uint8)
@@ -712,15 +717,16 @@ cdef class Matrix(Matrix0):
712
717
the magic :meth:`__array__` method) to convert Sage matrices
713
718
to numpy arrays::
714
719
715
- sage: import numpy # needs numpy
716
- sage: b = numpy.array(a); b # needs numpy
720
+ sage: # needs numpy
721
+ sage: import numpy
722
+ sage: b = numpy.array(a); b
717
723
array([[ 0, 1, 2, 3],
718
724
[ 4, 5, 6, 7],
719
725
[ 8, 9, 10, 11]])
720
- sage: b.dtype # needs numpy
726
+ sage: b.dtype
721
727
dtype('int32') # 32-bit
722
728
dtype('int64') # 64-bit
723
- sage: b.shape # needs numpy
729
+ sage: b.shape
724
730
(3, 4)
725
731
"""
726
732
import numpy
@@ -762,7 +768,7 @@ cdef class Matrix(Matrix0):
762
768
763
769
EXAMPLES::
764
770
765
- sage: M = Matrix(Integers(7), 2, 2, [5, 9, 13, 15]) ; M
771
+ sage: M = Matrix(Integers(7), 2, 2, [5, 9, 13, 15]); M
766
772
[5 2]
767
773
[6 1]
768
774
sage: M.lift()
@@ -806,7 +812,7 @@ cdef class Matrix(Matrix0):
806
812
807
813
EXAMPLES::
808
814
809
- sage: M = Matrix(Integers(8), 2, 4, range(8)) ; M
815
+ sage: M = Matrix(Integers(8), 2, 4, range(8)); M
810
816
[0 1 2 3]
811
817
[4 5 6 7]
812
818
sage: L = M.lift_centered(); L
@@ -1106,7 +1112,8 @@ cdef class Matrix(Matrix0):
1106
1112
sage: c = a.dense_columns(); c
1107
1113
[(x, 2/3*x), (x^2, x^5 + 1)]
1108
1114
sage: parent(c[1])
1109
- Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Rational Field
1115
+ Ambient free module of rank 2 over the principal ideal domain
1116
+ Univariate Polynomial Ring in x over Rational Field
1110
1117
1111
1118
TESTS:
1112
1119
@@ -1640,7 +1647,8 @@ cdef class Matrix(Matrix0):
1640
1647
[ 1 2/3 ]
1641
1648
[ y y^2 ]
1642
1649
sage: C. parent( )
1643
- Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in y over Rational Field
1650
+ Full MatrixSpace of 2 by 2 dense matrices over
1651
+ Univariate Polynomial Ring in y over Rational Field
1644
1652
1645
1653
Stacking a dense matrix atop a sparse one returns a sparse
1646
1654
matrix::
@@ -1911,7 +1919,8 @@ cdef class Matrix(Matrix0):
1911
1919
sage: C = B. augment( A) ; C
1912
1920
[ y y^2 1 2 ]
1913
1921
sage: C. parent( )
1914
- Full MatrixSpace of 1 by 4 dense matrices over Univariate Polynomial Ring in y over Rational Field
1922
+ Full MatrixSpace of 1 by 4 dense matrices over
1923
+ Univariate Polynomial Ring in y over Rational Field
1915
1924
1916
1925
sage: D = A. augment( B)
1917
1926
Traceback ( most recent call last) :
@@ -1922,7 +1931,8 @@ cdef class Matrix(Matrix0):
1922
1931
sage: F = E. augment( B) ; F
1923
1932
[ 1 2 y y^2 ]
1924
1933
sage: F. parent( )
1925
- Full MatrixSpace of 1 by 4 dense matrices over Univariate Polynomial Ring in y over Rational Field
1934
+ Full MatrixSpace of 1 by 4 dense matrices over
1935
+ Univariate Polynomial Ring in y over Rational Field
1926
1936
1927
1937
AUTHORS:
1928
1938
@@ -2098,8 +2108,8 @@ cdef class Matrix(Matrix0):
2098
2108
2099
2109
INPUT:
2100
2110
2101
- * ``drows`` - list of indices of rows to be deleted from self.
2102
- * ``check`` - checks whether any index in ``drows`` is out of range. Defaults to ``True`` .
2111
+ * ``drows`` -- list of indices of rows to be deleted from `` self`` .
2112
+ * ``check`` -- (boolean, default: ``True``); whether to check if any index in ``drows`` is out of range.
2103
2113
2104
2114
.. SEEALSO::
2105
2115
@@ -2161,7 +2171,7 @@ cdef class Matrix(Matrix0):
2161
2171
2162
2172
def matrix_from_rows_and_columns (self , rows , columns ):
2163
2173
"""
2164
- Return the matrix constructed from self from the given rows and
2174
+ Return the matrix constructed from `` self`` from the given rows and
2165
2175
columns.
2166
2176
2167
2177
EXAMPLES::
0 commit comments