properly catching the LinAlgError. also, prepping to change the run_baker method (more generic)
This commit is contained in:
parent
bd8f24d64f
commit
993c901cec
@ -30,7 +30,6 @@ phis = get_phis_3D(X, R.points)
|
|||||||
print "phi values (should all be positive): ", phis, sum(phis)
|
print "phi values (should all be positive): ", phis, sum(phis)
|
||||||
if [i for i in phis if i < 0.0]:
|
if [i for i in phis if i < 0.0]:
|
||||||
print "problems"
|
print "problems"
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
r = run_baker_3D(X, R, S)
|
r = run_baker_3D(X, R, S)
|
||||||
|
|
||||||
@ -40,7 +39,5 @@ print 'final', r['final']
|
|||||||
|
|
||||||
if abs(r['final'] - exact) <= abs(r['qlin'] - exact):
|
if abs(r['final'] - exact) <= abs(r['qlin'] - exact):
|
||||||
print "win"
|
print "win"
|
||||||
sys.exit(0)
|
|
||||||
else:
|
else:
|
||||||
print "failure"
|
print "failure"
|
||||||
sys.exit(2)
|
|
||||||
|
@ -27,7 +27,7 @@ def get_phis(X, R):
|
|||||||
])
|
])
|
||||||
try:
|
try:
|
||||||
phi = np.linalg.solve(A,b)
|
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
|
print >> sys.stderr, "warning: get_phis: calculation of phis yielded a linearly dependant system", e
|
||||||
raise smberror('get_phis')
|
raise smberror('get_phis')
|
||||||
phi = np.dot(np.linalg.pinv(A), b)
|
phi = np.dot(np.linalg.pinv(A), b)
|
||||||
@ -65,7 +65,7 @@ def get_phis_3D(X, r):
|
|||||||
])
|
])
|
||||||
try:
|
try:
|
||||||
phi = np.linalg.solve(A,b)
|
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
|
print >> sys.stderr, "warning: get_phis_3D: calculation of phis yielded a linearly dependant system", e
|
||||||
phi = np.dot(np.linalg.pinv(A), b)
|
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
|
# calculate values only for the simplex triangle
|
||||||
phi, qlin = qlinear(X, R)
|
phi, qlin = qlinear(X, R)
|
||||||
|
|
||||||
if [i for i in phi if i <= 0.0]:
|
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:
|
if len(S.points) == 0:
|
||||||
answer = {
|
answer = {
|
||||||
@ -152,7 +158,7 @@ def run_baker(X, R, S):
|
|||||||
# baker solve eq 10
|
# baker solve eq 10
|
||||||
try:
|
try:
|
||||||
(a, b, c) = np.linalg.solve(A,b)
|
(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
|
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)
|
(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
|
# calculate values only for the triangle
|
||||||
phi, qlin = qlinear_3D(X, R)
|
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:
|
if len(S.points) == 0:
|
||||||
answer = {
|
answer = {
|
||||||
'a': None,
|
'a': None,
|
||||||
|
@ -22,7 +22,7 @@ class TestSequenceFunctions(unittest.TestCase):
|
|||||||
[-1,-1], # 8
|
[-1,-1], # 8
|
||||||
]
|
]
|
||||||
self.q = [1, 0, 0, 0, 0, 0, 0, 0, 0]
|
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
|
self.accuracy = 8
|
||||||
|
|
||||||
def testImports(self):
|
def testImports(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user