mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-09 20:12:38 +02:00
caching now resets cache on error
This commit is contained in:
parent
3d6a69e5f0
commit
c6b1f513d3
1 changed files with 27 additions and 23 deletions
|
|
@ -52,6 +52,7 @@ class Cacher(object):
|
||||||
|
|
||||||
#if the result is cached, return the cached computation
|
#if the result is cached, return the cached computation
|
||||||
state = [all(a is b for a, b in itertools.izip_longest(args, cached_i)) for cached_i in self.cached_inputs]
|
state = [all(a is b for a, b in itertools.izip_longest(args, cached_i)) for cached_i in self.cached_inputs]
|
||||||
|
try:
|
||||||
if any(state):
|
if any(state):
|
||||||
i = state.index(True)
|
i = state.index(True)
|
||||||
if self.inputs_changed[i]:
|
if self.inputs_changed[i]:
|
||||||
|
|
@ -68,13 +69,16 @@ class Cacher(object):
|
||||||
[a.remove_observer(self, self.on_cache_changed) for a in args_ if a is not None]
|
[a.remove_observer(self, self.on_cache_changed) for a in args_ if a is not None]
|
||||||
self.inputs_changed.pop(0)
|
self.inputs_changed.pop(0)
|
||||||
self.cached_outputs.pop(0)
|
self.cached_outputs.pop(0)
|
||||||
|
|
||||||
#compute
|
#compute
|
||||||
self.cached_inputs.append(oa_all)
|
self.cached_inputs.append(oa_all)
|
||||||
self.cached_outputs.append(self.operation(*args, **kw))
|
self.cached_outputs.append(self.operation(*args, **kw))
|
||||||
self.inputs_changed.append(False)
|
self.inputs_changed.append(False)
|
||||||
[a.add_observer(self, self.on_cache_changed) for a in observable_args]
|
[a.add_observer(self, self.on_cache_changed) for a in observable_args]
|
||||||
return self.cached_outputs[-1]#return
|
return self.cached_outputs[-1]#return
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
self.reset()
|
||||||
|
|
||||||
def on_cache_changed(self, arg):
|
def on_cache_changed(self, arg):
|
||||||
"""
|
"""
|
||||||
|
|
@ -84,7 +88,7 @@ class Cacher(object):
|
||||||
"""
|
"""
|
||||||
self.inputs_changed = [any([a is arg for a in args]) or old_ic for args, old_ic in zip(self.cached_inputs, self.inputs_changed)]
|
self.inputs_changed = [any([a is arg for a in args]) or old_ic for args, old_ic in zip(self.cached_inputs, self.inputs_changed)]
|
||||||
|
|
||||||
def reset(self, obj):
|
def reset(self):
|
||||||
"""
|
"""
|
||||||
Totally reset the cache
|
Totally reset the cache
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue