mirror of https://github.com/openXC7/prjxray.git
timfuz: begin converting to fractions
Signed-off-by: John McMaster <johndmcmaster@gmail.com>
This commit is contained in:
parent
b3f881a54c
commit
8c5436916c
|
|
@ -8,7 +8,7 @@ import math
|
|||
from collections import OrderedDict
|
||||
|
||||
# check for issues that may be due to round off error
|
||||
STRICT = 1
|
||||
STRICT = 0
|
||||
|
||||
def Adi2matrix_random(A_ubd, b_ub, names):
|
||||
# random assignment
|
||||
|
|
@ -92,6 +92,8 @@ def row_sub_syms(row, sub_json, verbose=False):
|
|||
assert pivot not in row
|
||||
|
||||
# after all constants are applied, the row should end up positive?
|
||||
# numeric precision issues may limit this
|
||||
# Ex: AssertionError: ('PIP_BSW_2ELSING0', -2.220446049250313e-16)
|
||||
if STRICT:
|
||||
for k, v in sorted(row.items()):
|
||||
assert v > 0, (k, v)
|
||||
|
|
|
|||
|
|
@ -12,8 +12,22 @@ import math
|
|||
import json
|
||||
import sympy
|
||||
from collections import OrderedDict
|
||||
from fractions import Fraction
|
||||
|
||||
STRICT = 1
|
||||
STRICT = 0
|
||||
|
||||
def fracr(r):
|
||||
DELTA = 0.0001
|
||||
|
||||
for i, x in enumerate(r):
|
||||
if type(x) is float:
|
||||
xi = int(x)
|
||||
assert abs(xi - x) < DELTA
|
||||
r[i] = xi
|
||||
return [Fraction(x) for x in r]
|
||||
|
||||
def fracm(m):
|
||||
return [fracr(r) for r in m]
|
||||
|
||||
class State(object):
|
||||
def __init__(self, Ads, drop_names=[]):
|
||||
|
|
@ -97,10 +111,13 @@ def comb_corr_sets(state, verbose=False):
|
|||
mnp = Anp2matrix(Anp)
|
||||
print('Matrix: %u rows x %u cols' % (len(mnp), len(mnp[0])))
|
||||
print('Converting np to sympy matrix')
|
||||
msym = sympy.Matrix(mnp)
|
||||
mfrac = fracm(mnp)
|
||||
print('mfrac', type(mfrac[0][0]))
|
||||
msym = sympy.Matrix(mfrac)
|
||||
print('Making rref')
|
||||
rref, pivots = msym.rref()
|
||||
|
||||
|
||||
if verbose:
|
||||
print('names')
|
||||
print(names)
|
||||
|
|
|
|||
Loading…
Reference in New Issue