Skip to content

Commit 929baf8

Browse files
authored
added dependency support for the set methods.
1 parent 204ebd1 commit 929baf8

1 file changed

Lines changed: 40 additions & 11 deletions

File tree

deeptrack/properties.py

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
import numpy as np
8282

8383
from .utils import get_kwarg_names
84-
from .backend.core import DeepTrackNode
84+
from deeptrack.backend.core import DeepTrackNode
8585

8686

8787
class Property(DeepTrackNode):
@@ -588,7 +588,7 @@ def __init__(
588588

589589
# 6) Define a default current function for steps >= 1.
590590
if current_value is not None:
591-
self.current = self.create_action(current_value,**kwargs)
591+
self.current = self.create_action(current_value, **kwargs)
592592
else:
593593
self.current = lambda _ID=(): None
594594

@@ -692,19 +692,48 @@ def set_sequence_length(
692692
value: Any,
693693
_ID: Tuple[int, ...] = ()
694694
) -> None:
695-
"""Sets the length of sequence to be resolved.
696-
...
697-
695+
"""Sets the `sequence_length` attribute of a sequence to be resolved.
696+
697+
Supports dependencies if `value` is a `Property`.
698+
699+
Parameters
700+
----------
701+
value : Any
702+
The value to store in `sequence_length`.
703+
_ID : Tuple[int, ...], optional
704+
A unique identifier that allows the property to keep separate
705+
histories for different parallel evaluations.
706+
698707
"""
699-
self.sequence_length = Property(value, _ID=_ID)
700708

709+
if isinstance(value, Property):
710+
self.sequence_length = Property(lambda _ID: value(_ID))
711+
self.sequence_length.add_dependency(value)
712+
else:
713+
self.sequence_length = Property(value, _ID=_ID)
701714

702715
def set_current_step(
703-
self,
704-
value:Any,
705-
_ID: Tuple[int, ...] = ()
716+
self,
717+
value: Any,
718+
_ID: Tuple[int, ...] = ()
706719
) -> None:
707-
"""Sets the current index of the sequence.
720+
"""Sets the `current_index` attribute of a sequence to be resolved.
721+
722+
Supports dependencies if `value` is a `Property`.
723+
724+
Parameters
725+
----------
726+
value : Any
727+
The value to store in `current_step`.
728+
729+
_ID : Tuple[int, ...], optional
730+
A unique identifier that allows the property to keep separate
731+
histories for different parallel evaluations.
708732
709733
"""
710-
self.sequence_step = Property(value, _ID=_ID)
734+
735+
if isinstance(value, Property): # For dependencies.
736+
self.sequence_step = Property(lambda _ID: value(_ID))
737+
self.sequence_step.add_dependency(value)
738+
else:
739+
self.sequence_step = Property(value, _ID=_ID)

0 commit comments

Comments
 (0)