Sqrt#

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

Bases: ElementwiseFeature

Apply the square root function elementwise.

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

For non-negative real values, it returns the usual square root. For negative inputs, the behavior depends on the backend: - NumPy may return nan or a complex result depending on dtype. - PyTorch raises an error unless the input is explicitly complex.

Parameters#

feature: Feature | None, optional

The input feature to which the square root function will be applied. If None, the function is applied directly to the input array or tensor.

Examples#

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

Use with NumPy directly:

>>> import numpy as np
>>> result = Sqrt()(np.array([0.0, 1.0, 4.0]))
>>> result
array([0., 1., 2.])

Use with PyTorch directly:

>>> import torch
>>> result = Sqrt()(torch.tensor([0.0, 1.0, 4.0]))
>>> result
tensor([0., 1., 2.])

Use in a pipeline with a NumPy value:

>>> value = dt.Value(value=np.array([0.0, 1.0, 4.0]))
>>> pipeline = value >> Sqrt()
>>> result = pipeline()
>>> result
array([0., 1., 2.])

Use in a pipeline with a PyTorch value:

>>> value = dt.Value(value=torch.tensor([0.0, 1.0, 4.0]))
>>> pipeline = value >> Sqrt()
>>> result = pipeline()
>>> result
tensor([0., 1., 2.])

These are equivalent to:

>>> pipeline = Sqrt(value)