added a better docstring and improved the memoize function

This commit is contained in:
Stephen McQuay 2011-05-07 16:06:14 -06:00
parent cbe1a778c9
commit 9e766d0355

View File

@ -196,10 +196,11 @@ def memoize(f):
"""
cache = {}
@wraps(f)
def memf(*x, **kargs):
def memf(simplex_size, nu):
x = (simplex_size, nu)
if x not in cache:
log.debug("adding to cache: %s", x)
cache[x] = f(*x, **kargs)
cache[x] = f(simplex_size, nu)
return cache[x]
return memf
@ -207,7 +208,8 @@ def memoize(f):
@memoize
def pattern(simplex_size, nu):
"""
my useful docstring
This function returns the pattern requisite to compose the error
approximation function, and the matrix B.
"""
log.debug("pattern: simplex: %d, order: %d" % (simplex_size, nu))
@ -215,7 +217,8 @@ def pattern(simplex_size, nu):
for i in itertools.product(xrange(simplex_size), repeat = nu):
if len(set(i)) !=1:
r.append(tuple(sorted(i)))
return list(set(r))
unique_r = list(set(r))
return unique_r
if __name__ == '__main__':