def assign_caches(self, caches=None): from sfepy.terms import cache_table, DataCaches self.caches = caches = get_default(caches, DataCaches()) if not hasattr(self, 'use_caches'): return ## print self.name for name, arg_lists in self.use_caches.iteritems(): ## print self.arg_names ## print name, arg_lists for args in arg_lists: ## Order should be handled in terms... args = copy(args) if len(args) and (type( args[-1] ) == dict): history_sizes = args.pop() else: history_sizes = None ans = [self.get_arg_name(arg, full=True, join='_') for arg in args] cname = '_'.join([name] + ans) ## print self.name, name, arg_lists, args, cname ## print history_sizes if caches.has_key(cname): caches[cname].merge_history_sizes(history_sizes) else: ## print 'new' try: constructor = cache_table[name] except: raise RuntimeError, 'cache not found! %s in %s'\ % (name, sorted(cache_table.keys())) cache = constructor(cname, ans, history_sizes) caches.insert_cache(cache) caches.insert_term(cname, self.name, ans)
def assign_term_caches(self, caches): """ History sizes for a particular cache instance are taken as maximum of history_sizes requirements of all terms using the instance. """ for term in self.terms: if not hasattr(term, "use_caches"): continue ## print term.name for name, arg_lists in term.use_caches.iteritems(): ## print term.arg_names ## print name, arg_lists for args in arg_lists: # Order should be handled in terms... args = copy(args) if type(args[-1]) == dict: history_sizes = args.pop() else: history_sizes = None ans = [term.get_arg_name(arg, full=True) for arg in args] cname = "_".join([name] + ans) ## print term.name, name, arg_lists, args, self.name, cname ## print history_sizes ## debug() if caches.has_key(cname): caches[cname].merge_history_sizes(history_sizes) else: ## print 'new' try: constructor = cache_table[name] except: raise RuntimeError, "cache not found! %s in %s" % (name, sorted(cache_table.keys())) cache = constructor(cname, ans, history_sizes) caches.insert_cache(cache) caches.insert_term(cname, term.name, ans) term.caches = caches