### replaced answer with a namedtuple

master
Stephen M. McQuay 8 years ago
parent
commit
0577356cd7
8 changed files with 94 additions and 82 deletions
1. +19
-24
interp/baker/__init__.py
2. +3
-3
interp/grid/__init__.py
3. +7
-0
interp/tools.py
4. +1
-1
test/all.py
5. +26
-14
test/baker2d.py
6. +5
-5
test/baker2dorder.py
7. +17
-18
test/cubic2d.py
8. +16
-17

#### + 3 - 3 interp/grid/__init__.pyView File

 @@ -6,7 +6,7 @@ from xml.dom.minidom import Document import numpy as np from scipy.spatial import KDTree from interp.baker import run_baker from interp.baker import interpolate from interp.baker import get_phis import interp @@ -136,9 +136,9 @@ class grid(object): return (r_mesh, s_mesh) def run_baker(self, X, order=2, extra_points=3): def interpolate(self, X, order=2, extra_points=3): (R, S) = self.get_simplex_and_nearest_points(X, extra_points) answer = run_baker(X, R, S, order) answer = interpolate(X, R, S, order) return answer def for_qhull_generator(self):

#### + 7 - 0 interp/tools.pyView File

 @@ -45,6 +45,10 @@ def baker_exact_3D(X): np.sin(z * np.pi / 2.0)), 2) return answer def exact_me(X, f): a = np.array([f(i) for i in X]) return a def friendly_exact_3D(X): x, y, z = X @@ -67,6 +71,9 @@ def improved_answer(answer, exact): else: return False def identical_points(a,b): return all(set(j[i] for j in a) \ == set(j[i] for j in b) for i in xrange(len(a[0]))) def improved(qlin, err, final, exact): if np.abs(final - exact) <= np.abs(qlin - exact):

#### + 1 - 1 test/all.pyView File

 @@ -21,4 +21,4 @@ if __name__ == '__main__': ] for test in tests: unittest.TextTestRunner(verbosity=3).run(test) unittest.TextTestRunner(verbosity=1).run(test)

#### + 5 - 5 test/baker2dorder.pyView File

 @@ -77,7 +77,7 @@ class Test(unittest.TestCase): self.phis, self.qlin = baker.qlinear(self.X, self.R, self.q) self.exact = exact_func(self.X) self.answer = baker.run_baker(self.X, self.R, self.answer = baker.interpolate(self.X, self.R, self.R_q, self.S, self.S_q) def test_R_contains_X(self): @@ -86,22 +86,22 @@ class Test(unittest.TestCase): def test_1(self): a, b, c, d, e, f = (0, 1, 1, 2, 2, 0) err = calculate_error_term(self, a, b, c, d, e, f) self.assertAlmostEqual(err, self.answer['error']) self.assertAlmostEqual(err, self.answer.error) def test_swap_first_elements(self): a, b, c, d, e, f = (1, 0, 1, 2, 2, 0) err = calculate_error_term(self, a, b, c, d, e, f) self.assertAlmostEqual(err, self.answer['error']) self.assertAlmostEqual(err, self.answer.error) def test_swap_two_pairs(self): a, b, c, d, e, f = (1, 2, 0, 1, 2, 0) err = calculate_error_term(self, a, b, c, d, e, f) self.assertAlmostEqual(err, self.answer['error']) self.assertAlmostEqual(err, self.answer.error) def test_swap_all_pairs(self): a, b, c, d, e, f = (0, 2, 0, 1, 2, 1) err = calculate_error_term(self, a, b, c, d, e, f) self.assertAlmostEqual(err, self.answer['error']) self.assertAlmostEqual(err, self.answer.error) if __name__ == '__main__':