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
+18 -4
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,