Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add memoization to dynamic Callable class #1063

Merged
merged 4 commits into from Jan 16, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+3 −33
Diff settings

Always

Just for now

Removed dimensionless_cache

  • Loading branch information...
Philipp Rudiger Philipp Rudiger
Philipp Rudiger authored and Philipp Rudiger committed Jan 15, 2017
commit 601d1f804bab35eedbf8d8469b53eab60747ff6f
Copy path View file
@@ -530,7 +530,6 @@ def __init__(self, callback, initial_items=None, **params):

self.call_mode = self._validate_mode()
self.mode = 'bounded' if self.call_mode == 'key' else 'open'
self._dimensionless_cache = False


def _initial_key(self):
@@ -778,7 +777,7 @@ def __getitem__(self, key):
try:
dimensionless = util.dimensionless_contents(get_nested_streams(self),
self.kdims, no_duplicates=False)
if (dimensionless and not self._dimensionless_cache):
if dimensionless:
raise KeyError('Using dimensionless streams disables DynamicMap cache')
cache = super(DynamicMap,self).__getitem__(key)
# Return selected cache items in a new DynamicMap
Copy path View file
@@ -128,29 +128,3 @@ def hierarchical(keys):
store1[v2].append(v1)
hierarchies.append(store2 if hierarchy else {})
return hierarchies


class dimensionless_cache(object):
"""
Context manager which temporarily enables lookup of frame in the
cache on a DynamicMap with dimensionless streams. Allows passing
any Dimensioned object which might contain a DynamicMap and
whether to enable the cache. This allows looking up an item
without triggering the callback. Useful when the object is looked
up multiple times as part of some processing pipeline.
"""

def __init__(self, obj, allow_cache_lookup=True):
self.obj = obj
self._allow_cache_lookup = allow_cache_lookup

def __enter__(self):
self.set_cache_flag(self._allow_cache_lookup)

def __exit__(self, exc_type, exc_val, exc_tb):
self.set_cache_flag(False)

def set_cache_flag(self, value):
self.obj.traverse(lambda x: setattr(x, '_dimensionless_cache', value),
['DynamicMap'])

Copy path View file
@@ -18,7 +18,6 @@
from ..core.options import Store, Compositor, SkipRendering
from ..core.overlay import NdOverlay
from ..core.spaces import HoloMap, DynamicMap
from ..core.traversal import dimensionless_cache
from ..core.util import stream_parameters
from ..element import Table
from .util import (get_dynamic_mode, initialize_sampled, dim_axis_label,
@@ -625,8 +624,7 @@ def _get_frame(self, key):
self.current_key = key
return self.current_frame
elif self.dynamic:
with dimensionless_cache(self.hmap, not self._force or not self.drawn):
key, frame = util.get_dynamic_item(self.hmap, self.dimensions, key)
key, frame = util.get_dynamic_item(self.hmap, self.dimensions, key)
traverse_setter(self, '_force', False)
if not isinstance(key, tuple): key = (key,)
key_map = dict(zip([d.name for d in self.hmap.kdims], key))
@@ -977,8 +975,7 @@ def _get_frame(self, key):
if d in item.dimensions('key')], key)
self.current_key = tuple(k[1] for k in dim_keys)
elif item.traverse(lambda x: x, [DynamicMap]):
with dimensionless_cache(item, not self._force or not self.drawn):
key, frame = util.get_dynamic_item(item, self.dimensions, key)
key, frame = util.get_dynamic_item(item, self.dimensions, key)
layout_frame[path] = frame
continue
elif self.uniform:
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.