mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-15 06:52:39 +02:00
[caching] first things first
This commit is contained in:
parent
24a34aee95
commit
6b2681d849
1 changed files with 9 additions and 9 deletions
|
|
@ -15,7 +15,7 @@ class Cacher(object):
|
||||||
self.limit = int(limit)
|
self.limit = int(limit)
|
||||||
self.ignore_args = ignore_args
|
self.ignore_args = ignore_args
|
||||||
self.force_kwargs = force_kwargs
|
self.force_kwargs = force_kwargs
|
||||||
self.operation=operation
|
self.operation = operation
|
||||||
self.order = collections.deque()
|
self.order = collections.deque()
|
||||||
self.cached_inputs = {} # point from cache_ids to a list of [ind_ids], which where used in cache cache_id
|
self.cached_inputs = {} # point from cache_ids to a list of [ind_ids], which where used in cache cache_id
|
||||||
self.logger = logging.getLogger("cache")
|
self.logger = logging.getLogger("cache")
|
||||||
|
|
@ -41,7 +41,7 @@ class Cacher(object):
|
||||||
|
|
||||||
def prepare_cache_id(self, combined_args_kw, ignore_args):
|
def prepare_cache_id(self, combined_args_kw, ignore_args):
|
||||||
"get the cacheid (conc. string of argument self.ids in order) ignoring ignore_args"
|
"get the cacheid (conc. string of argument self.ids in order) ignoring ignore_args"
|
||||||
cache_id = "".join(self.id(a) for i,a in enumerate(combined_args_kw) if i not in ignore_args)
|
cache_id = "".join(self.id(a) for i, a in enumerate(combined_args_kw) if i not in ignore_args)
|
||||||
self.logger.debug("cache_id={} was created".format(cache_id))
|
self.logger.debug("cache_id={} was created".format(cache_id))
|
||||||
return cache_id
|
return cache_id
|
||||||
|
|
||||||
|
|
@ -105,10 +105,10 @@ class Cacher(object):
|
||||||
inputs = self.combine_inputs(args, kw)
|
inputs = self.combine_inputs(args, kw)
|
||||||
cache_id = self.prepare_cache_id(inputs, self.ignore_args)
|
cache_id = self.prepare_cache_id(inputs, self.ignore_args)
|
||||||
# 2: if anything is not cachable, we will just return the operation, without caching
|
# 2: if anything is not cachable, we will just return the operation, without caching
|
||||||
if reduce(lambda a,b: a or (not (isinstance(b, Observable) or b is None)), inputs, False):
|
if reduce(lambda a, b: a or (not (isinstance(b, Observable) or b is None)), inputs, False):
|
||||||
self.logger.info("some inputs are not observable: returning without caching")
|
self.logger.info("some inputs are not observable: returning without caching")
|
||||||
self.logger.info(str(map(lambda x: isinstance(x, Observable) or x is None, inputs)))
|
self.logger.debug(str(map(lambda x: isinstance(x, Observable) or x is None, inputs)))
|
||||||
self.logger.info(str(map(repr, inputs)))
|
self.logger.debug(str(map(repr, inputs)))
|
||||||
return self.operation(*args, **kw)
|
return self.operation(*args, **kw)
|
||||||
# 3&4: check whether this cache_id has been cached, then has it changed?
|
# 3&4: check whether this cache_id has been cached, then has it changed?
|
||||||
try:
|
try:
|
||||||
|
|
@ -179,7 +179,7 @@ class Cacher_wrap(object):
|
||||||
return partial(self, obj)
|
return partial(self, obj)
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
obj = args[0]
|
obj = args[0]
|
||||||
#import ipdb;ipdb.set_trace()
|
# import ipdb;ipdb.set_trace()
|
||||||
try:
|
try:
|
||||||
caches = obj.__cachers
|
caches = obj.__cachers
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue