Abs#

class deeptrack.elementwise.Abs(feature: Feature | None = None, **kwargs: Any)#

Bases: ElementwiseFeature

Apply the absolute value function elementwise.

This feature applies xp.abs to each element in a NumPy array or a PyTorch tensor. It supports both direct input and pipeline composition.

For real-valued inputs, this is the absolute value. For complex-valued inputs, this is the magnitude.

Examples#

>>> import deeptrack as dt
>>> from deeptrack.elementwise import Abs

Use with NumPy directly:

>>> import numpy as np
>>> result = Abs()(np.array([-1.0, 0.0, 2.5]))
>>> result
array([1. , 0. , 2.5])

Use with PyTorch directly:

>>> import torch
>>> result = Abs()(torch.tensor([-1.0, 0.0, 2.5]))
>>> result
tensor([1.0000, 0.0000, 2.5000])

Use in a pipeline with a NumPy value:

>>> value = dt.Value(value=np.array([-3.0, 0.0, 3.0]))
>>> pipeline = value >> Abs()
>>> result = pipeline()
>>> result
array([3., 0., 3.])

Use in a pipeline with a PyTorch value:

>>> value = dt.Value(value=torch.tensor([-3.0, 0.0, 3.0]))
>>> pipeline = value >> Abs()
>>> result = pipeline()
>>> result
tensor([3., 0., 3.])

These are equivalent to:

>>> pipeline = Abs(value)