fn

absolute

Tensor
absolute(x: Tensor)
source

Element-wise absolute value.

Verbose alias of lucid.abs, exposed for parity with reference frameworks that publish both abs and absolute spellings of the same operation.

Parameters

xTensor
Input tensor. Any numeric dtype.

Returns

Tensor

Tensor of the same shape and dtype as x containing xi|x_i| element-wise.

Notes

Mathematical definition:

outi=xi\text{out}_i = |x_i|

The gradient is sign(xi)\operatorname{sign}(x_i); the sub-gradient at xi=0x_i = 0 is conventionally taken to be 0.

Examples

>>> import lucid
>>> x = lucid.tensor([-1.5, 0.0, 2.0])
>>> lucid.absolute(x)
Tensor([1.5, 0., 2.])