CacheTuple
- class hybrid_learning.datasets.caching.CacheTuple(*caches, return_none_if='any')[source]
Bases:
CacheCache the values of tuples using different caches. Given a descriptor and a tuple of objects, each value of the tuple is stored in a different cache under the given descriptor.
Can be used e.g. to store transformed pairs of (input, target) using two different caches.
Public Methods:
load(descriptor)Load all objects stored under
descriptorand return as tuple.put(descriptor, obj)Put
obj[i]intocaches[i]under keydescriptor.clear()Clear all caches in the tuple.
Return all descriptors that occur in any of the given caches.
Inherited from : py: class:Cache
put(descriptor, obj)Put
obj[i]intocaches[i]under keydescriptor.load(descriptor)Load all objects stored under
descriptorand return as tuple.put_batch(descriptors, objs)Store a batch of
objsin this cache using accordingdescriptors.load_batch(descriptors[, return_none_if])Load a batch of objects.
clear()Clear all caches in the tuple.
Return all descriptors that occur in any of the given caches.
as_dict()Return a dict with all cached descriptors and objects.
wrap(getitem[, descriptor_map])Add this cache to the deterministic function
getitem(which should have no side effects).Special Methods:
__init__(*caches[, return_none_if])Init.
__repr__()Return repr(self).
Inherited from : py: class:Cache
__repr__()Return repr(self).
__add__(other)Return a (cascaded) cache which will first lookup
selfthenotherwith default sync mode.__radd__(other)Return a (cascaded) cache which will first lookup
otherthenselfwith default sync mode.
- __init__(*caches, return_none_if='any')[source]
Init.
- Parameters
caches (Cache) – the caches to use to cache the values of given tuples
return_none_if (Union[str, int]) – see
return_none_if; may be one of'any', 'all', 'never', 1, 0, -1.
- descriptors()[source]
Return all descriptors that occur in any of the given caches.
Warning
This may be slow, as the descriptor sets need to be united. Instead collect the descriptors of one cache if you know the caches have the same descriptors:
tuple_cache.caches[0].descriptors().- Return type
- load(descriptor)[source]
Load all objects stored under
descriptorand return as tuple. ReturnNoneaccording to the setting ofreturn_none_if.
- return_none_if: int
Mode by which to return
Noneonload(). Possible modes:1/'any': ReturnNoneif any cache load returnsNone.0/'all': ReturnNoneif all cache loads returnNone.-1/'never': Do not returnNone, but always a tuple (possibly only holdingNonevalues).
The string specifiers will get mapped to integer values to increase speed.