Stack#
- class deeptrack.features.Stack(value: Any | Callable[[...], Any], **kwargs: Any)#
Bases:
FeatureStack the input and the value.
This feature combines the output of the input data (inputs) and the value produced by the specified feature (value). The resulting output is a list where the elements of the inputs and value are concatenated.
If B is a feature, Stack can be visualized as
>>> A >> Stack(B) = [*A(), *B()]
It is equivalent to using the & operator
>>> A & B
Parameters#
- value: PropertyLike[Any]
The feature or data to stack with the input data.
- **kwargs: Any
Additional arguments passed to the parent Feature class.
Attributes#
- __distributed__: bool
Set to False, indicating that this feature’s .get() method processes the entire input at once even if it is a list, rather than distributing calls for each item of the list.
Methods#
- get(inputs, value, _ID, **kwargs) -> list[Any]
Concatenate the inputs with the value.
Examples#
>>> import deeptrack as dt
Start by creating a pipeline using Stack:
>>> pipeline = dt.Value([1, 2, 3]) >> dt.Stack(value=[4, 5]) >>> pipeline.resolve() [1, 2, 3, 4, 5]
Equivalently, this pipeline can be created using:
>>> pipeline = dt.Value([1, 2, 3]) & [4, 5] >>> pipeline.resolve() [1, 2, 3, 4, 5]
Or:
>>> pipeline = [4, 5] & dt.Value([1, 2, 3]) # Different result >>> pipeline.resolve() [4, 5, 1, 2, 3]
Note#
If a feature is called directly, its result is cached internally. This can affect how it behaves when reused in chained pipelines. For example:
>>> stack_feature = dt.Stack(value=2) >>> _ = stack_feature(1) # Evaluate the feature and cache the output >>> (1 & stack_feature)() [1, 1, 2]
To ensure consistent behavior when reusing a feature after calling it, reset its state using instead:
>>> stack_feature = dt.Stack(value=2) >>> _ = stack_feature(1) >>> stack_feature.update() # clear cached state >>> (1 & stack_feature)() [1, 2]
Methods Summary
get(inputs, value, **kwargs)Concatenate the input with the value.
Methods Documentation
- get(inputs: Any | list[Any], value: Any | list[Any], **kwargs: Any) list[Any]#
Concatenate the input with the value.
It ensures that both the input (inputs) and the value (value) are treated as lists before concatenation.
Parameters#
- inputs: Any or list[Any]
The input data to stack. Can be a single element or a list.
- value: Any or list[Any]
The feature or data to stack with the input. Can be a single element or a list.
- **kwargs: Any
Additional keyword arguments (not used here).
Returns#
- list[Any]
A list containing all elements from image and value.