fn

signbit

Tensor
signbit(x: Tensor)
source

Element-wise sign-bit predicate.

Returns a boolean tensor that is True wherever x is strictly negative. The current implementation uses the strict inequality x < 0, so -0.0 reports False (i.e. the value is treated as zero rather than tested via IEEE 754 sign-bit inspection).

Parameters

xTensor
Input tensor. Any numeric dtype.

Returns

Tensor

Boolean tensor of the same shape as x.

Notes

Mathematical definition:

signbit(xi)={True,xi<0,False,xi0.\text{signbit}(x_i) = \begin{cases} \text{True}, & x_i < 0, \\ \text{False}, & x_i \geq 0. \end{cases}

Non-differentiable: the gradient is zero almost everywhere and the output dtype is boolean.

Examples

>>> import lucid
>>> x = lucid.tensor([-1.0, 0.0, 1.0])
>>> lucid.signbit(x)
Tensor([ True, False, False])