Log2#

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

Bases: ElementwiseFeature

Apply the base-2 logarithm function elementwise.

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

The input must be strictly positive. Passing zero or negative values will return -inf or NaN, and may raise warnings or errors depending on the backend.

Parameters#

feature: Feature | None, optional

The input feature to which the logarithm function with base 2 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 Log2

Use with NumPy directly:

>>> import numpy as np
>>> result = Log2()(np.array([1.0, 2.0, 4.0, 8.0]))
>>> result
array([0., 1., 2., 3.])

Use with PyTorch directly:

>>> import torch
>>> result = Log2()(torch.tensor([1.0, 2.0, 4.0, 8.0]))
>>> result
tensor([0., 1., 2., 3.])

Use in a pipeline with a NumPy value:

>>> value = dt.Value(value=np.array([1.0, 2.0, 4.0, 8.0]))
>>> pipeline = value >> Log2()
>>> result = pipeline()
>>> result
array([0., 1., 2., 3.])

Use in a pipeline with a PyTorch value:

>>> value = dt.Value(value=torch.tensor([1.0, 2.0, 4.0, 8.0]))
>>> pipeline = value >> Log2()
>>> result = pipeline()
>>> result
tensor([0., 1., 2., 3.])

These are equivalent to:

>>> pipeline = Log2(value)