Equals#

class deeptrack.features.Equals(b: Any | list[Any] | Callable[[...], Any | list[Any]] = 0, **kwargs: Any)#

Bases: ArithmeticOperationFeature

Determine whether input is equal to a given value.

This feature performs element-wise comparison between the input and a specified value.

Notes#

  • Unlike other arithmetic operators, Equals does not define __eq__ (==) and __req__ (==) in DeepTrackNode and Feature, as this would affect Python’s built-in identity comparison.

  • This means that the standard == operator is overloaded only for expressions involving Feature instances but not for comparisons involving regular Python objects.

  • Always use >> to apply Equals correctly in a feature chain.

Parameters#

b: PropertyLike[Any | list[Any]], optional

The value to compare (==) with the input. Defaults to 0.

**kwargs: Any

Additional keyword arguments passed to the parent constructor.

Examples#

>>> import deeptrack as dt

Start by creating a pipeline using Equals:

>>> pipeline = dt.Value([1, 2, 3]) >> dt.Equals(b=2)
>>> pipeline.resolve()
[False, True, False]

Or:

>>> input_values = [1, 2, 3]
>>> eq_feature = dt.Equals(value=2)
>>> output_values = eq_feature(input_values)
>>> output_values
[False, True, False]

These are the only correct ways to apply Equals in a pipeline.

The following approaches are incorrect:

Using == directly on a Feature instance does not work because Feature does not override __eq__:

>>> pipeline = dt.Value([1, 2, 3]) == 2  # Incorrect
>>> pipeline.resolve()
AttributeError: 'bool' object has no attribute 'resolve'

Similarly, directly calling Equals on an input feature immediately evaluates the comparison, returning a boolean instead of a Feature:

>>> pipeline = dt.Equals(b=2)(dt.Value([1, 2, 3]))  # Incorrect
>>> pipeline.resolve()
AttributeError: 'bool' object has no attribute 'resolve'