fn

frac

Tensor
frac(input: Tensor)
source

Element-wise fractional part.

Returns x - trunc(x) for each entry, preserving the sign of the input.

Parameters

inputTensor
Input tensor.

Returns

Tensor

Element-wise result with the same shape as input.

Notes

Mathematical definition:

outi=inputitrunc(inputi)\text{out}_i = \text{input}_i - \mathrm{trunc}(\text{input}_i)

Output lies in (1,1)(-1, 1). Gradient is one almost everywhere.

Examples

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