From bd8f24d64f84d104e3fe3d975e680c1eed8492cf Mon Sep 17 00:00:00 2001 From: Stephen Mardson McQuay Date: Fri, 19 Mar 2010 21:27:51 -0600 Subject: [PATCH] working on implementing the cubic interpolation. need to split that routine out of the run_baker method --- bin/driver.py | 2 +- bin/test.py | 2 +- lib/baker/baker.py | 16 ++++++++-------- test/baker.test.py | 17 +++++++++-------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/bin/driver.py b/bin/driver.py index b5c12eb..66aabb0 100755 --- a/bin/driver.py +++ b/bin/driver.py @@ -103,4 +103,4 @@ if __name__ == '__main__': errors.append(cur_error) print rms(errors) - print "%s of %s won" % (success, len(mesh_dest.points)) + print >>sys.stderr, "%s of %s won" % (success, len(mesh_dest.points)) diff --git a/bin/test.py b/bin/test.py index 5725805..4a73b28 100755 --- a/bin/test.py +++ b/bin/test.py @@ -27,7 +27,7 @@ exact = exact_func_3D(X) print "exact solution: %0.6f" % exact phis = get_phis_3D(X, R.points) -print "phi values (should all be positive): ", phis +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) diff --git a/lib/baker/baker.py b/lib/baker/baker.py index 5c3c026..84fe422 100644 --- a/lib/baker/baker.py +++ b/lib/baker/baker.py @@ -27,8 +27,8 @@ def get_phis(X, R): ]) try: phi = np.linalg.solve(A,b) - except: - print >> sys.stderr, "warning: get_phis: calculation of phis yielded a linearly dependant system" + except 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,8 +65,8 @@ def get_phis_3D(X, r): ]) try: phi = np.linalg.solve(A,b) - except: - print >> sys.stderr, "warning: get_phis_3D: calculation of phis yielded a linearly dependant system" + except 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) return phi @@ -152,8 +152,8 @@ def run_baker(X, R, S): # baker solve eq 10 try: (a, b, c) = np.linalg.solve(A,b) - except: - print >> sys.stderr, "warning: run_baker: linear calculation went bad, resorting to np.linalg.pinv" + except 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) error_term = a * phi[0] * phi[1]\ @@ -230,8 +230,8 @@ def run_baker_3D(X, R, S): # baker solve eq 10 try: (a, b, c, d, e, f) = np.linalg.solve(A,b) - except: - print >> sys.stderr, "warning: run_baker: linear calculation went bad, resorting to np.linalg.pinv" + 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, d, e, f) = np.dot(np.linalg.pinv(A), b) error_term = a * phi[0] * phi[1]\ diff --git a/test/baker.test.py b/test/baker.test.py index addfcaf..be0c934 100755 --- a/test/baker.test.py +++ b/test/baker.test.py @@ -23,6 +23,7 @@ class TestSequenceFunctions(unittest.TestCase): ] self.q = [1, 0, 0, 0, 0, 0, 0, 0, 0] self.X = [1.5, 10.25] + self.accuracy = 8 def testImports(self): import numpy @@ -36,9 +37,9 @@ class TestSequenceFunctions(unittest.TestCase): r = [[-1, -1], [0, 2], [1, -1]] result = baker.get_phis(X, r) - result = [round(i, 5) for i in result] + result = [round(i, self.accuracy) for i in result] - right_answer = [round(i, 5) for i in [1/3.0, 1/3.0, 1/3.0]] + right_answer = [round(i, self.accuracy) for i in [1/3.0, 1/3.0, 1/3.0]] for a,b in zip(result, right_answer): self.assertEqual(a,b) @@ -77,13 +78,13 @@ class TestSequenceFunctions(unittest.TestCase): self.q[size_of_simplex:size_of_simplex + extra_points]) answer = baker.run_baker(self.X, R, S) - a = round(answer['a'], 5) - b = round(answer['b'], 5) - c = round(answer['c'], 5) + a = round(answer['a'], self.accuracy) + b = round(answer['b'], self.accuracy) + c = round(answer['c'], self.accuracy) self.assertEqual(a, c) - self.assertEqual(c, round(0.00 , 5)) - self.assertEqual(b, round(1/3.0, 5)) + self.assertEqual(c, round(0.00 , self.accuracy)) + self.assertEqual(b, round(1/3.0, self.accuracy)) def testRunBaker_2(self): size_of_simplex = 3 @@ -144,4 +145,4 @@ class TestSequenceFunctions(unittest.TestCase): if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions) - unittest.TextTestRunner(verbosity=2).run(suite) + unittest.TextTestRunner(verbosity=3).run(suite)