Skip to content

Commit 6a3df3d

Browse files
JChonpcagiovannivolpemirjagranforsJiacheng HuangPwhsky
authored
Features: Store (#397)
* Update features.py * Update features.py * Update features.py * Update features.py * Update test_features.py * Update features.py * Value Update test_features.py Update features.py Update test_features.py Update features.py * Update test_features.py * remove __gpu_compatible__ * Update features.py * Update test_features.py * Update features.py * Update test_features.py * Update aberrations.py * Update optics.py * Update image.py * Update holography.py * Update features.py * Update features.py * Update test_features.py * Update features.py * Update test_features.py * Update features.py * Update test_features.py * Update features.py * Update test_features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update test_features.py * Update features.py * Update features.py * Update test_features.py * Update test_features.py * Update features.py * Update features.py * Update test_features.py * Update features.py * Update test_features.py * Update test_features.py * Update features.py * Update test_features.py * Update features.py * Update test_features.py * Update features.py * Update features.py * Update test_features.py * Update features.py * Update features.py * Update test_features.py * Update features.py * Update test_features.py * Update features.py * Update features.py * Update test_features.py * Update features.py * Update features.py * Update test_features.py * Update features.py * Update features.py * Update features.py * Update test_features.py * Update features.py * Update test_features.py * Update test_features.py * Update features.py * Update test_features.py * Update features.py * Update test_features.py * Update features.py * Update test_features.py * Update test_features.py * Update features.py * Update test_features.py * Update features.py * Update test_features.py * Update features.py * Update test_features.py * Update features.py * Update test_features.py * Update features.py * Update test_features.py * Update test_features.py * Update features.py * Update features.py * Update test_features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update _config.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update _config.py * Update features.py * Update features.py * Update features.py * Updated the documentation of features/__sub__ (#356) * updated documentation of features/__sub__ * minor changes * remove blank * Update documentation of features/__pow__ (#359) * Update documentation of features/__pow__ * Update * u --------- Co-authored-by: Jiacheng Huang <chonpcaacpnohc@gmail.com> * Update features.py * Update features.py * Update features.py * Update features.py * added get_backend() as a feature method + unittesting to switch and get backend (#360) * Update features.py * Update test_features.py * Sequences restructuring (#345) * features: added to_sequential() * refactoring: SequentialProperty * typo in type hint * added dependency support for the set methods. * docs for to_sequential() * Update features.py * Update features.py * Add files via upload * edits Update sequences.py Update properties.py Update sequences.py Update sequences.py Update DTAT341_sequences.ipynb * Update test_properties.py * Update properties.py * u * Update properties.py * Update test_properties.py * Update properties.py * Update __init__.py * Update properties.py * Update properties.py * Update features.py * Update features.py * Update sequences.py * documentation and type hints * import Optional, Dict * missing comma... * current attributes * fix: typo in docstring. * documentation for sequences * typo * Update sequences.py * : * future import * documentation * DTAT306: Added SequentialProperty Example. (#350) * Added SequentialProperty example * typo * set length & index in seqprop __init__ * variable rename: sequence_step <- sequence_index * variable rename: sequence_step <- sequence_index * Update test_properties.py with new variable name * update documentation of SequentialProperty * variable name change: current and initialization * Update test_properties.py * Update features.py * Update sequences.py * sampling rule in init. * attributes * Update properties.py * Update features.py * Update properties.py * Update test_sequences.py * Revert "Update test_sequences.py" This reverts commit 503ea57. * Update properties.py * Update test_sequences.py * sequentialproperty docs * markov chain example in properties tutorial * Update seq_prop names * Update features.py * Update properties.py * Update properties.py * Update properties.py * Update properties.py * Update properties.py * Update properties.py * removed duplicate method * added example in docs * Updated tutorial with new names and examples * Update unit test * Update test_properties.py * Variable name changes * Update test_sequences.py * sequentialproperty docs * markov chain example in properties tutorial * new sequentialproperty attribute names * removed duplicate method * added example in docs * Updated tutorial with new names and examples * Update unit test * Update test_properties.py * docs: example of to_sequential() * create_action in __init__ * Added Previous() to SequentialProperty * Removed previous from backend.core * removed upsample from unit tests * Specific imports * u * sequences type hints * Updated SequentialProperty example * comma * Update __init__.py * Update features.py * Update DTAT306_properties.ipynb * Update DTAT306_properties.ipynb * Update DTAT341_sequences.ipynb * Update DTAT306_properties.ipynb * Update properties.py * Update test_properties.py * Update test_properties.py * Update features.py * Update features.py * Update optics.py * Update sequences.py * Update properties.py * Update test_sequences.py * Update features.py --------- Co-authored-by: Giovanni Volpe <giovanni.volpe@physics.gu.se> Co-authored-by: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update features.py * Update augmentations.py * Update types.py * Update utils.py * Update types.py * Update test_features.py * Update test_utils.py * Update DTAT387_types.ipynb * u * Update types.py * Update DTAT301_features.ipynb * Update DTAT387_types.ipynb * Update DTAT306_properties.ipynb * Update DTAT301_features.ipynb * Update DTAT306_properties.ipynb * Update DTAT341_sequences.ipynb * Update features.py * Added more documentation for features/__rsub__ (#363) * Added more documentation for features/__rsub__ * Update features.py --------- Co-authored-by: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> * Added more documentation for features/__mul__ (#364) * Added more documentation for features/__mul__ * Update features.py --------- Co-authored-by: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> * Added more documentation to features/__rmul__ (#365) * Update features.py * Polish documentationof feature/__pow__ (#366) * Update documentation of features/__pow__ * Update * u * Polish 1. remove >>> 2. remove blank * u * u * Update features.py --------- Co-authored-by: Jiacheng Huang <chonpcaacpnohc@gmail.com> Co-authored-by: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> * Add documentation of features/__rpow__ (#367) * Add documentation of features/__rpow__ * u * u * u * u * Update features.py --------- Co-authored-by: Jiacheng Huang <chonpcaacpnohc@gmail.com> Co-authored-by: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> * polishing of sources initial polishing of sources * Update base.py * Update base.py * Update base.py * Update base.py * Update base.py * Update base.py * Update base.py * Update base.py * features: __truediv__ (#362) * implemented truediv and rtruediv * docstring clarification * removed white spaces and updated example * example update * Implemented feedback * Update features.py --------- Co-authored-by: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> * Update base.py * al/features/__rtruediv__ polishing (#369) * removed update(), added dynamic example for rtruediv * Update features.py * Update features.py --------- Co-authored-by: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> * Update features.py * features: __floordiv__ (#368) * added __floordiv__ * docs * Implemented feedback from Mirja * minor adjustments * updated example * Update features.py --------- Co-authored-by: mirjagranfors <mirja98granfors@gmail.com> Co-authored-by: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> * Update features.py * Update base.py * Update base.py * Update base.py * Update base.py * Update base.py * Update base.py * Update base.py * Update base.py * Update base.py * Update base.py * Features: ChannelFirst2d (#361) * documented channel2d func * unit tests: channelfirst2d * type hints * Update features.py * NDArray type hint * included Image type hint and xp usage * unit test checks for torch_available * Update features.py * u * docs * linebreak * docs * Update test_features.py * Update test_features.py * deprecation warning & tests * Added support for Image objects * Tests for image objects * docs * tests and axis compatibility * fix for repeated calls * revert changes to upscale * Implemented feedback --------- Co-authored-by: Giovanni Volpe <giovanni.volpe@physics.gu.se> * Update features.py * Create __init__.py * Create test_base.py * Update test_base.py * Update DTAT391A_sources.base.ipynb * Delete interface_v2.mp4 * Update DTAT391B_sources.folder.ipynb * Update folder.py * Update test_features.py * Update folder.py * Update folder.py * Update folder.py * Update folder.py * Create test_folder.py * Update test_folder.py * Update folder.py * Update folder.py * Update test_folder.py * Add docs of /features/__gt__ (#372) * add docs of feature/__gt__ * u * u code example * polish --------- Co-authored-by: Jiacheng Huang <chonpcaacpnohc@gmail.com> * Add docs of /features/__rgt__ (#373) * Add docs of features/__rgt__ * fix typo * polish * fix error * u * Update features.py --------- Co-authored-by: Jiacheng Huang <chonpcaacpnohc@gmail.com> Co-authored-by: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> * Add docs of /features/__lt__ (#374) * add docs of /features/__lt__ * u --------- Co-authored-by: Jiacheng Huang <chonpcaacpnohc@gmail.com> * Add docs of /features/__rlt__ (#375) * add docs of /features/__rlt__ * u * u * Update features.py --------- Co-authored-by: Jiacheng Huang <chonpcaacpnohc@gmail.com> Co-authored-by: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> * Update features.py * Add docs of /features/__le__ (#376) * add docs 0f /featuers/__le__ * u --------- Co-authored-by: Jiacheng Huang <chonpcaacpnohc@gmail.com> * Update features.py * Add docs of /features/__rle__ (#377) * add docs of /features/__rle__ * u * u * Update features.py --------- Co-authored-by: Jiacheng Huang <chonpcaacpnohc@gmail.com> Co-authored-by: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> * Update features.py * Update features.py * add docs of /features/__ge__ (#378) Co-authored-by: Jiacheng Huang <chonpcaacpnohc@gmail.com> * Update features.py * Add docs of /features/__rge__ (#379) * add docs 0f /features/__rge__ * u * u * right , * Update features.py --------- Co-authored-by: Jiacheng Huang <chonpcaacpnohc@gmail.com> Co-authored-by: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> * Add docs of /features/__xor__ (#382) * add docs of /features/__xor__ * remove blank spaces --------- Co-authored-by: Jiacheng Huang <chonpcaacpnohc@gmail.com> * Add docs of /features/__rand__ (#381) * add docs of /features/__rand__ * Update features.py --------- Co-authored-by: Jiacheng Huang <chonpcaacpnohc@gmail.com> Co-authored-by: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> * add docs of /features/__and__ (#380) Co-authored-by: Jiacheng Huang <chonpcaacpnohc@gmail.com> * Update features.py * Update /features/Store * u * uu * minor typos * formatting * uuuu * Update features.py --------- Co-authored-by: Giovanni Volpe <giovanni.volpe@physics.gu.se> Co-authored-by: Mirja Granfors <95694095+mirjagranfors@users.noreply.github.com> Co-authored-by: Jiacheng Huang <chonpcaacpnohc@gmail.com> Co-authored-by: Alex <95913221+Pwhsky@users.noreply.github.com> Co-authored-by: Giovanni Volpe <46021832+giovannivolpe@users.noreply.github.com> Co-authored-by: mirjagranfors <mirja98granfors@gmail.com>
1 parent fa5fe51 commit 6a3df3d

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

deeptrack/features.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def propagate_data_to_dependencies(
222222
"ChannelFirst2d",
223223
"Upscale", # TODO ***AL***
224224
"NonOverlapping", # TODO ***AL***
225-
"Store", # TODO ***JH***
225+
"Store",
226226
"Squeeze",
227227
"Unsqueeze",
228228
"ExpandDims",
@@ -8804,9 +8804,9 @@ def _resample_volume_position(
88048804
class Store(Feature):
88058805
"""Store the output of a feature for reuse.
88068806
8807-
The `Store` feature evaluates a given feature and stores its output in an
8808-
internal dictionary. Subsequent calls with the same key will return the
8809-
stored value unless the `replace` parameter is set to `True`. This enables
8807+
The `Store` feature evaluates a given feature and stores its output in an
8808+
internal dictionary. Subsequent calls with the same key will return the
8809+
stored value unless the `replace` parameter is set to `True`. This enables
88108810
caching and reuse of computed feature outputs.
88118811
88128812
Parameters
@@ -8815,10 +8815,10 @@ class Store(Feature):
88158815
The feature to evaluate and store.
88168816
key: Any
88178817
The key used to identify the stored output.
8818-
replace: bool, optional
8819-
If `True`, replaces the stored value with a new computation. It defaults
8820-
to `False`.
8821-
**kwargs:: dict of str to Any
8818+
replace: PropertyLike[bool], optional
8819+
If `True`, replaces the stored value with the current computation. It
8820+
defaults to `False`.
8821+
**kwargs: dict of str to Any
88228822
Additional keyword arguments passed to the parent `Feature` class.
88238823
88248824
Attributes
@@ -8852,12 +8852,16 @@ class Store(Feature):
88528852
>>> cached_output = store_feature(None, key="example", replace=False)
88538853
>>> print(cached_output == output)
88548854
True
8855+
>>> print(cached_output == value_feature())
8856+
False
88558857
88568858
Retrieve the stored value recomputing:
88578859
>>> value_feature.update()
88588860
>>> cached_output = store_feature(None, key="example", replace=True)
88598861
>>> print(cached_output == output)
88608862
False
8863+
>>> print(cached_output == value_feature())
8864+
True
88618865
88628866
"""
88638867

@@ -8867,7 +8871,7 @@ def __init__(
88678871
self: Store,
88688872
feature: Feature,
88698873
key: Any,
8870-
replace: bool = False,
8874+
replace: PropertyLike[bool] = False,
88718875
**kwargs: Any,
88728876
):
88738877
"""Initialize the Store feature.
@@ -8878,8 +8882,8 @@ def __init__(
88788882
The feature to evaluate and store.
88798883
key: Any
88808884
The key used to identify the stored output.
8881-
replace: bool, optional
8882-
If `True`, replaces the stored value with a new computation.
8885+
replace: PropertyLike[bool], optional
8886+
If `True`, replaces the stored value with a new computation.
88838887
It defaults to `False`.
88848888
**kwargs:: dict of str to Any
88858889
Additional keyword arguments passed to the parent `Feature` class.
@@ -8918,7 +8922,7 @@ def get(
89188922
"""
89198923

89208924
# Check if the value should be recomputed or retrieved from the store
8921-
if replace or not (key in self._store):
8925+
if replace or not key in self._store:
89228926
self._store[key] = self.feature()
89238927

89248928
# Return the stored or newly computed result

deeptrack/tests/test_features.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,10 +2408,35 @@ def test_Store(self):
24082408
value_feature.update()
24092409
cached_output = store_feature(None, key="example", replace=False)
24102410
self.assertEqual(cached_output, output)
2411+
self.assertNotEqual(cached_output, value_feature())
24112412

24122413
value_feature.update()
24132414
cached_output = store_feature(None, key="example", replace=True)
24142415
self.assertNotEqual(cached_output, output)
2416+
self.assertEqual(cached_output, value_feature())
2417+
2418+
if TORCH_AVAILABLE:
2419+
2420+
value_feature = features.Value(lambda: torch.rand(1))
2421+
2422+
store_feature = features.Store(
2423+
feature=value_feature, key="example"
2424+
)
2425+
2426+
output = store_feature(None, key="example", replace=False)
2427+
2428+
value_feature.update()
2429+
cached_output = store_feature(None, key="example", replace=False)
2430+
torch.testing.assert_close(cached_output, output)
2431+
with self.assertRaises(AssertionError):
2432+
torch.testing.assert_close(cached_output, value_feature())
2433+
2434+
value_feature.update()
2435+
cached_output = store_feature(None, key="example", replace=True)
2436+
with self.assertRaises(AssertionError):
2437+
torch.testing.assert_close(cached_output, output)
2438+
torch.testing.assert_close(cached_output, value_feature())
2439+
24152440

24162441

24172442
def test_Squeeze(self):

0 commit comments

Comments
 (0)