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

Commit fd35ef0

Browse files
author
Frédéric Chapoton
committed
python3 print in matrices folder
1 parent c04fdff commit fd35ef0

12 files changed

+90
-80
lines changed

Diff for: src/sage/matrix/benchmark.py

+40-38
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
The basic command syntax is as follows::
99
1010
sage: import sage.matrix.benchmark as b
11-
sage: print "starting"; import sys; sys.stdout.flush(); b.report([b.det_ZZ], 'Test', systems=['sage'])
11+
sage: print("starting"); import sys; sys.stdout.flush(); b.report([b.det_ZZ], 'Test', systems=['sage'])
1212
starting...
1313
======================================================================
1414
Test
1515
======================================================================
1616
...
1717
======================================================================
1818
"""
19+
from __future__ import print_function
20+
1921
from constructor import random_matrix, Matrix
2022
from sage.rings.all import ZZ, QQ, GF
2123
from sage.misc.misc import cputime
@@ -41,7 +43,7 @@ def report(F, title, systems = ['sage', 'magma'], **kwds):
4143
EXAMPLES::
4244
4345
sage: import sage.matrix.benchmark as b
44-
sage: print "starting"; import sys; sys.stdout.flush(); b.report([b.det_ZZ], 'Test', systems=['sage'])
46+
sage: print("starting"); import sys; sys.stdout.flush(); b.report([b.det_ZZ], 'Test', systems=['sage'])
4547
starting...
4648
======================================================================
4749
Test
@@ -52,15 +54,15 @@ def report(F, title, systems = ['sage', 'magma'], **kwds):
5254
import os
5355
if len(systems) > 2:
5456
raise NotImplementedError("at most two systems ('sage' or 'magma')")
55-
print '='*70
56-
print ' '*10 + title
57-
print '='*70
57+
print('=' * 70)
58+
print(' ' * 10 + title)
59+
print('=' * 70)
5860
os.system('uname -a')
59-
print '\n'
61+
print('\n')
6062
for f in F:
61-
print "-"*70
62-
print f.__doc__.strip()
63-
print ('%15s'*len(systems))%tuple(systems)
63+
print("-"*70)
64+
print(f.__doc__.strip())
65+
print(('%15s' * len(systems)) % tuple(systems))
6466
w = []
6567
for s in systems:
6668
alarm(timeout)
@@ -77,8 +79,8 @@ def report(F, title, systems = ['sage', 'magma'], **kwds):
7779
w.append(w[0]/w[1])
7880

7981
w = tuple(w)
80-
print ('%15.3f'*len(w))%w
81-
print '='*70
82+
print(('%15.3f'*len(w)) % w)
83+
print('=' * 70)
8284

8385

8486
#######################################################################
@@ -97,7 +99,7 @@ def report_ZZ(**kwds):
9799
EXAMPLES::
98100
99101
sage: import sage.matrix.benchmark as b
100-
sage: print "starting"; import sys; sys.stdout.flush(); b.report_ZZ(systems=['sage']) # long time (15s on sage.math, 2012)
102+
sage: print("starting"); import sys; sys.stdout.flush(); b.report_ZZ(systems=['sage']) # long time (15s on sage.math, 2012)
101103
starting...
102104
======================================================================
103105
Dense benchmarks over ZZ
@@ -147,7 +149,7 @@ def nullspace_ZZ(n=200, min=0, max=2**32, system='sage'):
147149
K := Kernel(A);
148150
s := Cputime(t);
149151
"""%(n,min,max)
150-
if verbose: print code
152+
if verbose: print(code)
151153
magma.eval(code)
152154
return float(magma.eval('s'))
153155
else:
@@ -186,7 +188,7 @@ def charpoly_ZZ(n=100, min=0, max=9, system='sage'):
186188
K := CharacteristicPolynomial(A);
187189
s := Cputime(t);
188190
"""%(n,min,max)
189-
if verbose: print code
191+
if verbose: print(code)
190192
magma.eval(code)
191193
return float(magma.eval('s'))
192194
else:
@@ -225,7 +227,7 @@ def rank_ZZ(n=700, min=0, max=9, system='sage'):
225227
K := Rank(A);
226228
s := Cputime(t);
227229
"""%(n,min,max)
228-
if verbose: print code
230+
if verbose: print(code)
229231
magma.eval(code)
230232
return float(magma.eval('s'))
231233
else:
@@ -263,7 +265,7 @@ def rank2_ZZ(n=400, min=0, max=2**64, system='sage'):
263265
K := Rank(A);
264266
s := Cputime(t);
265267
"""%(n,min,max)
266-
if verbose: print code
268+
if verbose: print(code)
267269
magma.eval(code)
268270
return float(magma.eval('s'))
269271
else:
@@ -303,7 +305,7 @@ def smithform_ZZ(n=128, min=0, max=9, system='sage'):
303305
K := ElementaryDivisors(A);
304306
s := Cputime(t);
305307
"""%(n,min,max)
306-
if verbose: print code
308+
if verbose: print(code)
307309
magma.eval(code)
308310
return float(magma.eval('s'))
309311
else:
@@ -348,7 +350,7 @@ def matrix_multiply_ZZ(n=300, min=-9, max=9, system='sage', times=1):
348350
end for;
349351
s := Cputime(t);
350352
"""%(n,min,max,times)
351-
if verbose: print code
353+
if verbose: print(code)
352354
magma.eval(code)
353355
return float(magma.eval('s'))/times
354356
else:
@@ -394,7 +396,7 @@ def matrix_add_ZZ(n=200, min=-9, max=9, system='sage', times=50):
394396
end for;
395397
s := Cputime(t);
396398
"""%(n,min,max,times)
397-
if verbose: print code
399+
if verbose: print(code)
398400
magma.eval(code)
399401
return float(magma.eval('s'))/times
400402
else:
@@ -454,7 +456,7 @@ def det_ZZ(n=200, min=1, max=100, system='sage'):
454456
d := Determinant(A);
455457
s := Cputime(t);
456458
"""%(n,min,max)
457-
if verbose: print code
459+
if verbose: print(code)
458460
magma.eval(code)
459461
return float(magma.eval('s'))
460462
else:
@@ -494,7 +496,7 @@ def det_QQ(n=300, num_bound=10, den_bound=10, system='sage'):
494496
d := Determinant(A);
495497
s := Cputime(t);
496498
"""%(n,-num_bound, num_bound, den_bound)
497-
if verbose: print code
499+
if verbose: print(code)
498500
magma.eval(code)
499501
return float(magma.eval('s'))
500502
else:
@@ -541,7 +543,7 @@ def vecmat_ZZ(n=300, min=-9, max=9, system='sage', times=200):
541543
end for;
542544
s := Cputime(t);
543545
"""%(n,min,max,times)
544-
if verbose: print code
546+
if verbose: print(code)
545547
magma.eval(code)
546548
return float(magma.eval('s'))/times
547549
else:
@@ -572,7 +574,7 @@ def report_GF(p=16411, **kwds):
572574
EXAMPLES::
573575
574576
sage: import sage.matrix.benchmark as b
575-
sage: print "starting"; import sys; sys.stdout.flush(); b.report_GF(systems=['sage'])
577+
sage: print("starting"); import sys; sys.stdout.flush(); b.report_GF(systems=['sage'])
576578
starting...
577579
======================================================================
578580
Dense benchmarks over GF with prime 16411
@@ -617,7 +619,7 @@ def nullspace_GF(n=300, p=16411, system='sage'):
617619
K := Kernel(A);
618620
s := Cputime(t);
619621
"""%(n,p)
620-
if verbose: print code
622+
if verbose: print(code)
621623
magma.eval(code)
622624
return magma.eval('s')
623625
else:
@@ -656,7 +658,7 @@ def charpoly_GF(n=100, p=16411, system='sage'):
656658
K := CharacteristicPolynomial(A);
657659
s := Cputime(t);
658660
"""%(n,p)
659-
if verbose: print code
661+
if verbose: print(code)
660662
magma.eval(code)
661663
return magma.eval('s')
662664
else:
@@ -697,7 +699,7 @@ def matrix_add_GF(n=1000, p=16411, system='sage',times=100):
697699
end for;
698700
s := Cputime(t);
699701
"""%(n,p,p,times)
700-
if verbose: print code
702+
if verbose: print(code)
701703
magma.eval(code)
702704
return magma.eval('s')
703705
else:
@@ -743,7 +745,7 @@ def matrix_multiply_GF(n=100, p=16411, system='sage', times=3):
743745
end for;
744746
s := Cputime(t);
745747
"""%(n,p,times)
746-
if verbose: print code
748+
if verbose: print(code)
747749
magma.eval(code)
748750
return float(magma.eval('s'))/times
749751
else:
@@ -780,7 +782,7 @@ def rank_GF(n=500, p=16411, system='sage'):
780782
K := Rank(A);
781783
s := Cputime(t);
782784
"""%(n,p)
783-
if verbose: print code
785+
if verbose: print(code)
784786
magma.eval(code)
785787
return float(magma.eval('s'))
786788
else:
@@ -816,7 +818,7 @@ def rank2_GF(n=500, p=16411, system='sage'):
816818
K := Rank(A);
817819
s := Cputime(t);
818820
"""%(n,p)
819-
if verbose: print code
821+
if verbose: print(code)
820822
magma.eval(code)
821823
return float(magma.eval('s'))
822824
else:
@@ -853,7 +855,7 @@ def det_GF(n=400, p=16411 , system='sage'):
853855
d := Determinant(A);
854856
s := Cputime(t);
855857
"""%(n,p)
856-
if verbose: print code
858+
if verbose: print(code)
857859
magma.eval(code)
858860
return float(magma.eval('s'))
859861
else:
@@ -915,7 +917,7 @@ def echelon_QQ(n=100, min=0, max=9, system='sage'):
915917
K := EchelonForm(A);
916918
s := Cputime(t);
917919
"""%(n,min,max)
918-
if verbose: print code
920+
if verbose: print(code)
919921
magma.eval(code)
920922
return float(magma.eval('s'))
921923
else:
@@ -954,7 +956,7 @@ def inverse_QQ(n=100, min=0, max=9, system='sage'):
954956
K := A^(-1);
955957
s := Cputime(t);
956958
"""%(n,min,max)
957-
if verbose: print code
959+
if verbose: print(code)
958960
magma.eval(code)
959961
return float(magma.eval('s'))
960962
else:
@@ -1000,7 +1002,7 @@ def matrix_multiply_QQ(n=100, bnd=2, system='sage', times=1):
10001002
end for;
10011003
s := Cputime(t);
10021004
"""%(n, A.name(), times)
1003-
if verbose: print code
1005+
if verbose: print(code)
10041006
magma.eval(code)
10051007
return float(magma.eval('s'))/times
10061008
else:
@@ -1037,7 +1039,7 @@ def det_hilbert_QQ(n=80, system='sage'):
10371039
s := Cputime(tinit);
10381040
delete h;
10391041
"""%n
1040-
if verbose: print code
1042+
if verbose: print(code)
10411043
magma.eval(code)
10421044
return float(magma.eval('s'))
10431045

@@ -1071,7 +1073,7 @@ def invert_hilbert_QQ(n=40, system='sage'):
10711073
s := Cputime(tinit);
10721074
delete h;
10731075
"""%n
1074-
if verbose: print code
1076+
if verbose: print(code)
10751077
magma.eval(code)
10761078
return float(magma.eval('s'))
10771079

@@ -1114,7 +1116,7 @@ def MatrixVector_QQ(n=1000,h=100,system='sage',times=1):
11141116
end for;
11151117
s := Cputime(t);
11161118
"""%(n,h,times)
1117-
if verbose: print code
1119+
if verbose: print(code)
11181120
magma.eval(code)
11191121
return float(magma.eval('s'))
11201122
else:
@@ -1162,7 +1164,7 @@ def nullspace_RR(n=300, min=0, max=10, system='sage'):
11621164
K := Kernel(A);
11631165
s := Cputime(t);
11641166
"""%(n,min,max)
1165-
if verbose: print code
1167+
if verbose: print(code)
11661168
magma.eval(code)
11671169
return float(magma.eval('s'))
11681170
else:
@@ -1202,7 +1204,7 @@ def nullspace_RDF(n=300, min=0, max=10, system='sage'):
12021204
K := Kernel(A);
12031205
s := Cputime(t);
12041206
"""%(n,min,max)
1205-
if verbose: print code
1207+
if verbose: print(code)
12061208
magma.eval(code)
12071209
return float(magma.eval('s'))
12081210
else:

Diff for: src/sage/matrix/echelon_matrix.pyx

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Echelon matrices over finite fields.
99
# the License, or (at your option) any later version.
1010
# http://www.gnu.org/licenses/
1111
#*****************************************************************************
12+
from __future__ import print_function
1213

1314
from sage.matrix.matrix0 cimport Matrix
1415

@@ -38,9 +39,9 @@ def reduced_echelon_matrix_iterator(K, k, n, bint sparse=False, bint copy=True,
3839
sage: from sage.matrix.echelon_matrix import reduced_echelon_matrix_iterator
3940
sage: it = reduced_echelon_matrix_iterator(GF(2),2,3)
4041
sage: for m in it:
41-
....: print m
42-
....: print m.pivots()
43-
....: print "*******"
42+
....: print(m)
43+
....: print(m.pivots())
44+
....: print("*******")
4445
[1 0 0]
4546
[0 1 0]
4647
(0, 1)

Diff for: src/sage/matrix/matrix0.pyx

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ EXAMPLES::
2121
# (at your option) any later version.
2222
# http://www.gnu.org/licenses/
2323
#*****************************************************************************
24+
from __future__ import print_function
2425

2526
from cpython cimport *
2627

@@ -1634,7 +1635,7 @@ cdef class Matrix(sage.structure.element.Matrix):
16341635
sage: A = matrix([[1,2], [3,4], [5,6]])
16351636
sage: A.__repr__()
16361637
'[1 2]\n[3 4]\n[5 6]'
1637-
sage: print A
1638+
sage: print(A)
16381639
[1 2]
16391640
[3 4]
16401641
[5 6]
@@ -1644,7 +1645,7 @@ cdef class Matrix(sage.structure.element.Matrix):
16441645
sage: A = random_matrix(ZZ, 100)
16451646
sage: A.__repr__()
16461647
'100 x 100 dense matrix over Integer Ring'
1647-
sage: print A
1648+
sage: print(A)
16481649
100 x 100 dense matrix over Integer Ring
16491650
16501651
When a big matrix returned, include a hint on how to get the entries.
@@ -4252,9 +4253,9 @@ cdef class Matrix(sage.structure.element.Matrix):
42524253
self.echelon_form()
42534254
x = self.fetch('pivots')
42544255
if x is None:
4255-
print self
4256-
print self.nrows()
4257-
print self.dict()
4256+
print(self)
4257+
print(self.nrows())
4258+
print(self.dict())
42584259
raise RuntimeError("BUG: matrix pivots should have been set but weren't, matrix parent = '%s'"%self.parent())
42594260
return tuple(x)
42604261

0 commit comments

Comments
 (0)