latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.functional.round
- tensorplay.functional.round(input, *, decimals=0, out=None) Tensor[source]
Rounds elements of
inputto the nearest integer.For integer inputs, follows the array-api convention of returning a copy of the input tensor. The return type of output is same as that of input’s dtype.
Note
This function implements the “round half to even” to break ties when a number is equidistant from two integers (e.g. round(2.5) is 2).
When the :attr:`decimals` argument is specified the algorithm used is similar to NumPy’s around. This algorithm is fast but inexact and it can easily overflow for low precision dtypes. Eg. round(tensor([10000], dtype=tensorplay.float16), decimals=3) is inf.
See also
tensorplay.ceil(), which rounds up.tensorplay.floor(), which rounds down.tensorplay.trunc(), which rounds towards zero.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> tensorplay.round(tensorplay.tensor((4.7, -2.3, 9.1, -7.7))) tensor([ 5., -2., 9., -8.]) >>> # Values equidistant from two integers are rounded towards the >>> # the nearest even value (zero is treated as even) >>> tensorplay.round(tensorplay.tensor([-0.5, 0.5, 1.5, 2.5])) tensor([-0., 0., 2., 2.]) >>> # A positive decimals argument rounds to the to that decimal place >>> tensorplay.round(tensorplay.tensor([0.1234567]), decimals=3) tensor([0.1230]) >>> # A negative decimals argument rounds to the left of the decimal >>> tensorplay.round(tensorplay.tensor([1200.1234567]), decimals=-3) tensor([1000.])
Help improve this page
Found an error, an unclear step, or a missing example?

