replaced answer with a namedtuple

This commit is contained in:
Stephen M. McQuay
2011-09-17 15:39:01 -06:00
parent 837a72b246
commit 0577356cd7
8 changed files with 94 additions and 82 deletions
+19 -24
View File
@@ -1,8 +1,9 @@
import numpy as np
from collections import namedtuple
from functools import wraps
import itertools
import numpy as np
import interp
AGGRESSIVE_ERROR_SOLVE = True
@@ -10,6 +11,8 @@ RAISE_PATHOLOGICAL_EXCEPTION = False
__version__ = interp.__version__
Answer = namedtuple("Answer", ['qlin', 'final', 'error', 'abc'])
def get_phis(X, R):
"""
@@ -124,7 +127,7 @@ def get_error(phi, R, R_q, S, S_q, order=2):
return error_term, abc
def run_baker(X, R, R_q, S, S_q, order=2):
def interpolate(X, R, R_q, S=None, S_q=None, order=2):
"""
This is the main function to call to get an interpolation to X from the
input meshes
@@ -132,23 +135,22 @@ def run_baker(X, R, R_q, S, S_q, order=2):
X -- the destination point
R = Simplex
R_q = q values at R
S = extra points
S_q = q values at S
order - order of interpolation - 1
"""
answer = {
'qlin': None,
'error': None,
'final': None,
}
qlin=None
error_term=None
final=None
abc={}
# calculate values only for the simplex triangle
phi, qlin = qlinear(X, R, R_q)
if order == 1:
answer['qlin'] = qlin
answer['final'] = qlin
return answer
elif order in xrange(2, 11):
if order in xrange(2, 11) and S:
error_term, abc = get_error(phi, R, R_q, S, S_q, order)
# if a pathological vertex configuration was encountered and
@@ -157,20 +159,13 @@ def run_baker(X, R, R_q, S, S_q, order=2):
if (error_term is None) and (abc is None):
if RAISE_PATHOLOGICAL_EXCEPTION:
raise np.linalg.LinAlgError("Pathological Vertex Config")
answer['qlin'] = qlin
answer['final'] = qlin
return answer
else:
else:
final = qlin + error_term
elif order not in xrange(2,11):
raise Exception('unsupported order "%d" for baker method' % order)
q_final = qlin + error_term
answer['qlin'] = qlin
answer['error'] = error_term
answer['final'] = q_final
answer['abc'] = abc
return answer
return Answer(qlin=qlin, error=error_term, final=final, abc=abc)
def memoize(f):