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

Commit

Permalink
python3 print in matrices folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric Chapoton committed May 3, 2016
1 parent c04fdff commit fd35ef0
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 80 deletions.
78 changes: 40 additions & 38 deletions src/sage/matrix/benchmark.py
Expand Up @@ -8,14 +8,16 @@
The basic command syntax is as follows::
sage: import sage.matrix.benchmark as b
sage: print "starting"; import sys; sys.stdout.flush(); b.report([b.det_ZZ], 'Test', systems=['sage'])
sage: print("starting"); import sys; sys.stdout.flush(); b.report([b.det_ZZ], 'Test', systems=['sage'])
starting...
======================================================================
Test
======================================================================
...
======================================================================
"""
from __future__ import print_function

from constructor import random_matrix, Matrix
from sage.rings.all import ZZ, QQ, GF
from sage.misc.misc import cputime
Expand All @@ -41,7 +43,7 @@ def report(F, title, systems = ['sage', 'magma'], **kwds):
EXAMPLES::
sage: import sage.matrix.benchmark as b
sage: print "starting"; import sys; sys.stdout.flush(); b.report([b.det_ZZ], 'Test', systems=['sage'])
sage: print("starting"); import sys; sys.stdout.flush(); b.report([b.det_ZZ], 'Test', systems=['sage'])
starting...
======================================================================
Test
Expand All @@ -52,15 +54,15 @@ def report(F, title, systems = ['sage', 'magma'], **kwds):
import os
if len(systems) > 2:
raise NotImplementedError("at most two systems ('sage' or 'magma')")
print '='*70
print ' '*10 + title
print '='*70
print('=' * 70)
print(' ' * 10 + title)
print('=' * 70)
os.system('uname -a')
print '\n'
print('\n')
for f in F:
print "-"*70
print f.__doc__.strip()
print ('%15s'*len(systems))%tuple(systems)
print("-"*70)
print(f.__doc__.strip())
print(('%15s' * len(systems)) % tuple(systems))
w = []
for s in systems:
alarm(timeout)
Expand All @@ -77,8 +79,8 @@ def report(F, title, systems = ['sage', 'magma'], **kwds):
w.append(w[0]/w[1])

w = tuple(w)
print ('%15.3f'*len(w))%w
print '='*70
print(('%15.3f'*len(w)) % w)
print('=' * 70)


#######################################################################
Expand All @@ -97,7 +99,7 @@ def report_ZZ(**kwds):
EXAMPLES::
sage: import sage.matrix.benchmark as b
sage: print "starting"; import sys; sys.stdout.flush(); b.report_ZZ(systems=['sage']) # long time (15s on sage.math, 2012)
sage: print("starting"); import sys; sys.stdout.flush(); b.report_ZZ(systems=['sage']) # long time (15s on sage.math, 2012)
starting...
======================================================================
Dense benchmarks over ZZ
Expand Down Expand Up @@ -147,7 +149,7 @@ def nullspace_ZZ(n=200, min=0, max=2**32, system='sage'):
K := Kernel(A);
s := Cputime(t);
"""%(n,min,max)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))
else:
Expand Down Expand Up @@ -186,7 +188,7 @@ def charpoly_ZZ(n=100, min=0, max=9, system='sage'):
K := CharacteristicPolynomial(A);
s := Cputime(t);
"""%(n,min,max)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))
else:
Expand Down Expand Up @@ -225,7 +227,7 @@ def rank_ZZ(n=700, min=0, max=9, system='sage'):
K := Rank(A);
s := Cputime(t);
"""%(n,min,max)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))
else:
Expand Down Expand Up @@ -263,7 +265,7 @@ def rank2_ZZ(n=400, min=0, max=2**64, system='sage'):
K := Rank(A);
s := Cputime(t);
"""%(n,min,max)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))
else:
Expand Down Expand Up @@ -303,7 +305,7 @@ def smithform_ZZ(n=128, min=0, max=9, system='sage'):
K := ElementaryDivisors(A);
s := Cputime(t);
"""%(n,min,max)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))
else:
Expand Down Expand Up @@ -348,7 +350,7 @@ def matrix_multiply_ZZ(n=300, min=-9, max=9, system='sage', times=1):
end for;
s := Cputime(t);
"""%(n,min,max,times)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))/times
else:
Expand Down Expand Up @@ -394,7 +396,7 @@ def matrix_add_ZZ(n=200, min=-9, max=9, system='sage', times=50):
end for;
s := Cputime(t);
"""%(n,min,max,times)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))/times
else:
Expand Down Expand Up @@ -454,7 +456,7 @@ def det_ZZ(n=200, min=1, max=100, system='sage'):
d := Determinant(A);
s := Cputime(t);
"""%(n,min,max)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))
else:
Expand Down Expand Up @@ -494,7 +496,7 @@ def det_QQ(n=300, num_bound=10, den_bound=10, system='sage'):
d := Determinant(A);
s := Cputime(t);
"""%(n,-num_bound, num_bound, den_bound)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))
else:
Expand Down Expand Up @@ -541,7 +543,7 @@ def vecmat_ZZ(n=300, min=-9, max=9, system='sage', times=200):
end for;
s := Cputime(t);
"""%(n,min,max,times)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))/times
else:
Expand Down Expand Up @@ -572,7 +574,7 @@ def report_GF(p=16411, **kwds):
EXAMPLES::
sage: import sage.matrix.benchmark as b
sage: print "starting"; import sys; sys.stdout.flush(); b.report_GF(systems=['sage'])
sage: print("starting"); import sys; sys.stdout.flush(); b.report_GF(systems=['sage'])
starting...
======================================================================
Dense benchmarks over GF with prime 16411
Expand Down Expand Up @@ -617,7 +619,7 @@ def nullspace_GF(n=300, p=16411, system='sage'):
K := Kernel(A);
s := Cputime(t);
"""%(n,p)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return magma.eval('s')
else:
Expand Down Expand Up @@ -656,7 +658,7 @@ def charpoly_GF(n=100, p=16411, system='sage'):
K := CharacteristicPolynomial(A);
s := Cputime(t);
"""%(n,p)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return magma.eval('s')
else:
Expand Down Expand Up @@ -697,7 +699,7 @@ def matrix_add_GF(n=1000, p=16411, system='sage',times=100):
end for;
s := Cputime(t);
"""%(n,p,p,times)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return magma.eval('s')
else:
Expand Down Expand Up @@ -743,7 +745,7 @@ def matrix_multiply_GF(n=100, p=16411, system='sage', times=3):
end for;
s := Cputime(t);
"""%(n,p,times)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))/times
else:
Expand Down Expand Up @@ -780,7 +782,7 @@ def rank_GF(n=500, p=16411, system='sage'):
K := Rank(A);
s := Cputime(t);
"""%(n,p)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))
else:
Expand Down Expand Up @@ -816,7 +818,7 @@ def rank2_GF(n=500, p=16411, system='sage'):
K := Rank(A);
s := Cputime(t);
"""%(n,p)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))
else:
Expand Down Expand Up @@ -853,7 +855,7 @@ def det_GF(n=400, p=16411 , system='sage'):
d := Determinant(A);
s := Cputime(t);
"""%(n,p)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))
else:
Expand Down Expand Up @@ -915,7 +917,7 @@ def echelon_QQ(n=100, min=0, max=9, system='sage'):
K := EchelonForm(A);
s := Cputime(t);
"""%(n,min,max)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))
else:
Expand Down Expand Up @@ -954,7 +956,7 @@ def inverse_QQ(n=100, min=0, max=9, system='sage'):
K := A^(-1);
s := Cputime(t);
"""%(n,min,max)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))
else:
Expand Down Expand Up @@ -1000,7 +1002,7 @@ def matrix_multiply_QQ(n=100, bnd=2, system='sage', times=1):
end for;
s := Cputime(t);
"""%(n, A.name(), times)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))/times
else:
Expand Down Expand Up @@ -1037,7 +1039,7 @@ def det_hilbert_QQ(n=80, system='sage'):
s := Cputime(tinit);
delete h;
"""%n
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))

Expand Down Expand Up @@ -1071,7 +1073,7 @@ def invert_hilbert_QQ(n=40, system='sage'):
s := Cputime(tinit);
delete h;
"""%n
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))

Expand Down Expand Up @@ -1114,7 +1116,7 @@ def MatrixVector_QQ(n=1000,h=100,system='sage',times=1):
end for;
s := Cputime(t);
"""%(n,h,times)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))
else:
Expand Down Expand Up @@ -1162,7 +1164,7 @@ def nullspace_RR(n=300, min=0, max=10, system='sage'):
K := Kernel(A);
s := Cputime(t);
"""%(n,min,max)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))
else:
Expand Down Expand Up @@ -1202,7 +1204,7 @@ def nullspace_RDF(n=300, min=0, max=10, system='sage'):
K := Kernel(A);
s := Cputime(t);
"""%(n,min,max)
if verbose: print code
if verbose: print(code)
magma.eval(code)
return float(magma.eval('s'))
else:
Expand Down
7 changes: 4 additions & 3 deletions src/sage/matrix/echelon_matrix.pyx
Expand Up @@ -9,6 +9,7 @@ Echelon matrices over finite fields.
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
from __future__ import print_function

from sage.matrix.matrix0 cimport Matrix

Expand Down Expand Up @@ -38,9 +39,9 @@ def reduced_echelon_matrix_iterator(K, k, n, bint sparse=False, bint copy=True,
sage: from sage.matrix.echelon_matrix import reduced_echelon_matrix_iterator
sage: it = reduced_echelon_matrix_iterator(GF(2),2,3)
sage: for m in it:
....: print m
....: print m.pivots()
....: print "*******"
....: print(m)
....: print(m.pivots())
....: print("*******")
[1 0 0]
[0 1 0]
(0, 1)
Expand Down
11 changes: 6 additions & 5 deletions src/sage/matrix/matrix0.pyx
Expand Up @@ -21,6 +21,7 @@ EXAMPLES::
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
from __future__ import print_function

from cpython cimport *

Expand Down Expand Up @@ -1634,7 +1635,7 @@ cdef class Matrix(sage.structure.element.Matrix):
sage: A = matrix([[1,2], [3,4], [5,6]])
sage: A.__repr__()
'[1 2]\n[3 4]\n[5 6]'
sage: print A
sage: print(A)
[1 2]
[3 4]
[5 6]
Expand All @@ -1644,7 +1645,7 @@ cdef class Matrix(sage.structure.element.Matrix):
sage: A = random_matrix(ZZ, 100)
sage: A.__repr__()
'100 x 100 dense matrix over Integer Ring'
sage: print A
sage: print(A)
100 x 100 dense matrix over Integer Ring
When a big matrix returned, include a hint on how to get the entries.
Expand Down Expand Up @@ -4252,9 +4253,9 @@ cdef class Matrix(sage.structure.element.Matrix):
self.echelon_form()
x = self.fetch('pivots')
if x is None:
print self
print self.nrows()
print self.dict()
print(self)
print(self.nrows())
print(self.dict())
raise RuntimeError("BUG: matrix pivots should have been set but weren't, matrix parent = '%s'"%self.parent())
return tuple(x)

Expand Down

0 comments on commit fd35ef0

Please sign in to comment.