properly catching the LinAlgError. also, prepping to change the run_baker method (more generic)

This commit is contained in:
Stephen Mardson McQuay 2010-03-20 11:34:24 -06:00
parent bd8f24d64f
commit 993c901cec
3 changed files with 19 additions and 8 deletions

View File

@ -30,7 +30,6 @@ phis = get_phis_3D(X, R.points)
print "phi values (should all be positive): ", phis, sum(phis)
if [i for i in phis if i < 0.0]:
print "problems"
sys.exit(1)
r = run_baker_3D(X, R, S)
@ -40,7 +39,5 @@ print 'final', r['final']
if abs(r['final'] - exact) <= abs(r['qlin'] - exact):
print "win"
sys.exit(0)
else:
print "failure"
sys.exit(2)

View File

@ -27,7 +27,7 @@ def get_phis(X, R):
])
try:
phi = np.linalg.solve(A,b)
except LinAlgError as e:
except np.linalg.LinAlgError as e:
print >> sys.stderr, "warning: get_phis: calculation of phis yielded a linearly dependant system", e
raise smberror('get_phis')
phi = np.dot(np.linalg.pinv(A), b)
@ -65,7 +65,7 @@ def get_phis_3D(X, r):
])
try:
phi = np.linalg.solve(A,b)
except LinAlgError as e:
except np.linalg.LinAlgError as e:
print >> sys.stderr, "warning: get_phis_3D: calculation of phis yielded a linearly dependant system", e
phi = np.dot(np.linalg.pinv(A), b)
@ -113,8 +113,14 @@ def run_baker(X, R, S):
# calculate values only for the simplex triangle
phi, qlin = qlinear(X, R)
if [i for i in phi if i <= 0.0]:
print "failure"
s = "this is not a containing simplex:\n"
s += " X: %s\n" % X
s += " R: %s\n" % R
s += " phi: %s, sum(%0.4e)\n" % (phi, sum(phi))
print >> sys.stderr, s
raise smberror("not containing simplex")
if len(S.points) == 0:
answer = {
@ -152,7 +158,7 @@ def run_baker(X, R, S):
# baker solve eq 10
try:
(a, b, c) = np.linalg.solve(A,b)
except LinAlgError as e:
except np.linalg.LinAlgError as e:
print >> sys.stderr, "warning: run_baker: linear calculation went bad, resorting to np.linalg.pinv", e
(a, b, c) = np.dot(np.linalg.pinv(A), b)
@ -187,6 +193,14 @@ def run_baker_3D(X, R, S):
# calculate values only for the triangle
phi, qlin = qlinear_3D(X, R)
if [i for i in phi if i <= 0.0]:
s = "this is not a containing simplex:\n"
s += " X: %s\n" % X
s += " R: %s\n" % R
s += " phi: %s, sum(%0.4e)\n" % (phi, sum(phi))
print >> sys.stderr, s
raise smberror("not containing simplex")
if len(S.points) == 0:
answer = {
'a': None,

View File

@ -22,7 +22,7 @@ class TestSequenceFunctions(unittest.TestCase):
[-1,-1], # 8
]
self.q = [1, 0, 0, 0, 0, 0, 0, 0, 0]
self.X = [1.5, 10.25]
self.X = [0.5, 0.25]
self.accuracy = 8
def testImports(self):