fn

trunc

Tensor
trunc(input: Tensor)
source

Element-wise truncation toward zero.

Removes the fractional part, returning the integer-valued float nearest to zero.

Parameters

inputTensor
Input tensor.

Returns

Tensor

Element-wise result with the same shape as input.

Notes

Mathematical definition:

outi=sgn(xi)xi\text{out}_i = \mathrm{sgn}(x_i)\,\lfloor |x_i| \rfloor

Equivalent to floor for positive inputs and ceil for negative inputs.

Examples

>>> import lucid
>>> x = lucid.tensor([1.0, 2.0, 3.0])
>>> lucid.trunc(x)
Tensor([...])