ElementwiseFeature#

class deeptrack.elementwise.ElementwiseFeature(function: Callable[[Any], Any], feature: Feature | None = None, function_name: str | None = None, **kwargs: Any)#

Bases: Feature

Base class for applying NumPy or PyTorch functions elementwise.

This class wraps a backend function (e.g., np.sin, torch.exp) and applies it elementwise to the output of another Feature.

If no input feature is provided, the function is applied directly to the input passed during resolution.

Parameters#

function: Callable[[array], array] | Callable[[tensor], tensor]

A backend-specific function (e.g., np.sin, torch.abs) or a backend-agnostic function (e.g., xp.sin, xp.abs) that will be applied elementwise to the input NumPy array or PyTorch tensor.

feature: Feature | None, optional

The input feature to be transformed. If provided, the function is applied to the output of this feature. If None, the function is applied directly to the input passed during evaluation.

Attributes#

__distributed__: bool

It overrides the default behavior to disable distributed resolution if a feature is chained. This ensures the transformation is computed locally.

Methods#

get(data, **kwargs) -> array

It applies the stored function to the input, optionally resolving the wrapped feature first.

Methods Summary

get()

Apply the stored function.

Methods Documentation

get(data: ndarray[tuple[int, ...], dtype[Any]], **kwargs: Any) ndarray[tuple[int, ...], dtype[Any]]#
get(data: Tensor, **kwargs: Any) Tensor

Apply the stored function.

It applies the stored function to the input or the result of the wrapped feature.

Parameters#

data: array

The input data to process. If feature was provided at initialization, this argument is ignored and the output of the wrapped feature is used instead.

**kwargs: Any

Additional keyword arguments for compatibility.

Returns#

array

The result of applying the elementwise function.