memoized the pattern function

This commit is contained in:
Stephen McQuay 2011-04-03 11:09:03 -06:00
parent e65f67893d
commit a732d82a98

View File

@ -204,6 +204,16 @@ def _samples_ur(items, k, offset = 0):
selections = [[items[i]]*count for i,count in enumerate(sample)]
yield tuple([x + offset for sel in selections for x in sel])
def memoize(f):
cache = {}
def memf(*x, **kargs):
if x not in cache:
print >>sys.stderr, x, kargs
cache[x] = f(*x, **kargs)
return cache[x]
return memf
@memoize
def pattern(power, phicount, offset = 0):
log.debug("(power = %s, phicount = %s)" % (power, phicount))
r = []