Store#
- class deeptrack.features.Store(feature: Feature, key: Any | Callable[[...], Any], replace: bool | Callable[[...], bool] = False, **kwargs: Any)#
Bases:
FeatureStore the output of a feature for reuse.
Store evaluates a given feature and stores its output in an internal dictionary. Subsequent calls with the same key will return the stored value unless the replace parameter is set to True. This enables caching and reuse of computed feature outputs.
Parameters#
- feature: Feature
The feature to evaluate and store.
- key: PropertyLike[Any]
The key used to identify the stored output.
- replace: PropertyLike[bool], optional
If True, replaces the stored value with the current computation. Defaults to False.
- **kwargs: Any
Additional keyword arguments passed to the parent Feature class.
Attributes#
- __distributed__: bool
Always False for Store, as it handles caching locally.
- _store: dict[tuple[Any, tuple[int, …]], Any]
A dictionary used to store the outputs of the evaluated feature.
Methods#
- get(inputs, key, replace, _ID, **kwargs) -> Any
Evaluate and store the feature output, or return the cached result.
Examples#
>>> import deeptrack as dt
Create a Store feature with a key:
>>> import numpy as np >>> >>> value_feature = dt.Value(lambda: np.random.rand()) >>> store_feature = dt.Store(feature=value_feature, key="example")
Retrieve and store the value:
>>> output = store_feature(None) # replace=False >>> output 0.16627384166489168
Retrieve the stored value without recomputing:
>>> value_feature.new() 0.6541155683335725
>>> cached_output = store_feature(None) # replace=False >>> cached_output 0.16627384166489168
Retrieve the stored value while recomputing:
>>> value_feature.new() 0.26025510106604566
>>> cached_output = store_feature(None, replace=True) >>> cached_output 0.26025510106604566
Methods Summary
get(inputs, key, replace[, _ID])Evaluate and store the feature output, or return the cached result.
Methods Documentation
- get(inputs: Any, key: Any, replace: bool, _ID: tuple[int, ...] = (), **kwargs: Any) Any#
Evaluate and store the feature output, or return the cached result.
Parameters#
- inputs: Any
Inputs to the feature.
- key: Any
The key used to identify the stored output.
- replace: bool
If True, replaces the stored value with a new computation.
- _ID: tuple[int, …], optional
The unique identifier for the current execution. Defaults to ().
- **kwargs: Any
Additional keyword arguments passed to the feature.
Returns#
- Any
The stored output or a newly computed result.