mirror of https://github.com/openXC7/prjxray.git
timfuz: perf tests
Signed-off-by: John McMaster <johndmcmaster@gmail.com>
This commit is contained in:
parent
9ff07f4278
commit
b4874d2cf9
|
|
@ -14,8 +14,9 @@ import sympy
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from fractions import Fraction
|
from fractions import Fraction
|
||||||
import random
|
import random
|
||||||
|
from sympy import Rational
|
||||||
|
|
||||||
def fracr(r):
|
def intr(r):
|
||||||
DELTA = 0.0001
|
DELTA = 0.0001
|
||||||
|
|
||||||
for i, x in enumerate(r):
|
for i, x in enumerate(r):
|
||||||
|
|
@ -23,11 +24,25 @@ def fracr(r):
|
||||||
xi = int(x)
|
xi = int(x)
|
||||||
assert abs(xi - x) < DELTA
|
assert abs(xi - x) < DELTA
|
||||||
r[i] = xi
|
r[i] = xi
|
||||||
|
|
||||||
|
def fracr(r):
|
||||||
|
intr(r)
|
||||||
return [Fraction(x) for x in r]
|
return [Fraction(x) for x in r]
|
||||||
|
|
||||||
def fracm(m):
|
def fracm(m):
|
||||||
return [fracr(r) for r in m]
|
return [fracr(r) for r in m]
|
||||||
|
|
||||||
|
def symratr(r):
|
||||||
|
intr(r)
|
||||||
|
return [Rational(x) for x in r]
|
||||||
|
|
||||||
|
def symratm(m):
|
||||||
|
return [symratr(r) for r in m]
|
||||||
|
|
||||||
|
def intm(m):
|
||||||
|
[intr(r) for r in m]
|
||||||
|
return m
|
||||||
|
|
||||||
def create_matrix(rows, cols):
|
def create_matrix(rows, cols):
|
||||||
ret = np.zeros((rows, cols))
|
ret = np.zeros((rows, cols))
|
||||||
for rowi in range(rows):
|
for rowi in range(rows):
|
||||||
|
|
@ -43,7 +58,7 @@ def create_matrix_sparse(rows, cols):
|
||||||
ret[rowi][coli] = random.randint(1, 10)
|
ret[rowi][coli] = random.randint(1, 10)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def run(rows=35, cols=200, verbose=False, encoding='np', sparse=False):
|
def run(rows=35, cols=200, verbose=False, encoding='np', sparse=False, normalize_last=True):
|
||||||
random.seed(0)
|
random.seed(0)
|
||||||
if sparse:
|
if sparse:
|
||||||
mnp = create_matrix_sparse(rows, cols)
|
mnp = create_matrix_sparse(rows, cols)
|
||||||
|
|
@ -52,12 +67,17 @@ def run(rows=35, cols=200, verbose=False, encoding='np', sparse=False):
|
||||||
#print(mnp[0])
|
#print(mnp[0])
|
||||||
|
|
||||||
if encoding == 'fraction':
|
if encoding == 'fraction':
|
||||||
mfrac = fracm(mnp)
|
msym = sympy.Matrix(fracm(mnp))
|
||||||
msym = sympy.Matrix(mfrac)
|
|
||||||
elif encoding == 'np':
|
elif encoding == 'np':
|
||||||
msym = sympy.Matrix(mnp)
|
msym = sympy.Matrix(mnp)
|
||||||
|
elif encoding == 'sympy':
|
||||||
|
msym = sympy.Matrix(symratm(mnp))
|
||||||
|
# this actually produces float results
|
||||||
|
elif encoding == 'int':
|
||||||
|
msym = sympy.Matrix(intm(mnp))
|
||||||
else:
|
else:
|
||||||
assert 0, 'bad encoding: %s' % encoding
|
assert 0, 'bad encoding: %s' % encoding
|
||||||
|
print(type(msym[0]), str(msym[0]))
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print('names')
|
print('names')
|
||||||
|
|
@ -65,12 +85,13 @@ def run(rows=35, cols=200, verbose=False, encoding='np', sparse=False):
|
||||||
print('Matrix')
|
print('Matrix')
|
||||||
sympy.pprint(msym)
|
sympy.pprint(msym)
|
||||||
|
|
||||||
print('%s matrix, %u rows x %u cols, sparse: %s' % (encoding, len(mnp), len(mnp[0]), sparse))
|
print('%s matrix, %u rows x %u cols, sparse: %s, normlast: %s' % (encoding, len(mnp), len(mnp[0]), sparse, normalize_last))
|
||||||
bench = Benchmark()
|
bench = Benchmark()
|
||||||
try:
|
try:
|
||||||
rref, pivots = msym.rref()
|
rref, pivots = msym.rref(normalize_last=normalize_last)
|
||||||
finally:
|
finally:
|
||||||
print('rref exiting after %s' % bench)
|
print('rref exiting after %s' % bench)
|
||||||
|
print(type(rref[0]), str(rref[0]))
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print('Pivots')
|
print('Pivots')
|
||||||
|
|
@ -90,10 +111,11 @@ def main():
|
||||||
parser.add_argument('--sparse', action='store_true', help='')
|
parser.add_argument('--sparse', action='store_true', help='')
|
||||||
parser.add_argument('--rows', type=int, help='')
|
parser.add_argument('--rows', type=int, help='')
|
||||||
parser.add_argument('--cols', type=int, help='')
|
parser.add_argument('--cols', type=int, help='')
|
||||||
|
parser.add_argument('--normalize-last', type=int, help='')
|
||||||
parser.add_argument('--encoding', default='np', help='')
|
parser.add_argument('--encoding', default='np', help='')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
run(encoding=args.encoding, rows=args.rows, cols=args.cols, sparse=args.sparse, verbose=args.verbose)
|
run(encoding=args.encoding, rows=args.rows, cols=args.cols, sparse=args.sparse, normalize_last=bool(args.normalize_last), verbose=args.verbose)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue