Round#
- class deeptrack.elementwise.Round(feature: Feature | None = None, **kwargs: Any)#
Bases:
ElementwiseFeatureApply the rounding function elementwise.
This feature applies xp.round to each element in a NumPy array or a PyTorch tensor. It supports both direct input and pipeline composition.
This function rounds to the nearest integer. For NumPy, ties round to the even number (bankers’ rounding). For PyTorch, ties round away from zero.
Parameters#
- feature: Feature | None, optional
The input feature to which the round 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 Round
Use with NumPy directly:
>>> import numpy as np >>> >>> result = Round()(np.array([-1.5, -0.5, 0.5, 1.5])) >>> result array([-2., -0., 0., 2.])
Use with PyTorch directly:
>>> import torch >>> >>> result = Round()(torch.tensor([-1.5, -0.5, 0.5, 1.5])) >>> result tensor([-2., -1., 1., 2.])
Use in a pipeline with a NumPy value:
>>> value = dt.Value(value=np.array([-1.5, -0.5, 0.5, 1.5])) >>> pipeline = value >> Round() >>> result = pipeline() >>> result array([-2., -0., 0., 2.])
Use in a pipeline with a PyTorch value:
>>> value = dt.Value(value=torch.tensor([-1.5, -0.5, 0.5, 1.5])) >>> pipeline = value >> Round() >>> result = pipeline() >>> result tensor([-2., -1., 1., 2.])
These are equivalent to:
>>> pipeline = Round(value)