ArithmeticOperationFeature#

class deeptrack.features.ArithmeticOperationFeature(op: Callable[[Any, Any], Any], value: float | int | list[float | int] = 0, **kwargs: dict[str, Any])#

Bases: Feature

Applies an arithmetic operation element-wise to inputs.

This feature performs an arithmetic operation (e.g., addition, subtraction, multiplication) on the input data. The inputs can be single values or lists of values. If a list is passed, the operation is applied to each element. If both inputs are lists of different lengths, the shorter list is cycled.

Parameters#

op: Callable[[Any, Any], Any]

The arithmetic operation to apply, such as a built-in operator (operator.add, operator.mul) or a custom callable.

value: float or int or list of float or int, optional

The second operand for the operation. Defaults to 0. If a list is provided, the operation will apply element-wise.

**kwargs: dict of str to Any

Additional keyword arguments passed to the parent Feature.

Attributes#

__distributed__: bool

Indicates that this feature’s get(…) method processes the input as a whole (False) rather than distributing calls for individual items.

__gpu_compatible__: bool

Specifies that the feature is compatible with GPU processing (True).

Methods#

get(image: Any | list of Any, value: float | int | list[float] | int, **kwargs: dict[str, Any]) -> list[Any]

Apply the arithmetic operation element-wise to the input data.

Examples#

>>> import deeptrack as dt
>>> import operator

Define a simple addition operation: >>> addition = dt.ArithmeticOperationFeature(operator.add, value=10)

Create a list of input values: >>> input_values = [1, 2, 3, 4]

Apply the operation: >>> output_values = addition(input_values) >>> print(output_values) [11, 12, 13, 14]

Methods Summary

get(image, value, **kwargs)

Apply the operation element-wise to the input data.

Methods Documentation

get(image: Any | list[Any], value: float | int | list[float | int], **kwargs: Any) list[Any]#

Apply the operation element-wise to the input data.

Parameters#

image: Any or list of Any

The input data, either a single value or a list of values, to be transformed by the arithmetic operation.

value: float, int, or list of float or int

The second operand(s) for the operation. If a single value is provided, it is broadcast to match the input size. If a list is provided, it will be cycled to match the length of the input list.

**kwargs: dict of str to Any

Additional parameters or property overrides. These are generally unused in this context but provided for compatibility with the Feature interface.

Returns#

list of Any

A list containing the results of applying the operation to the input data element-wise.