fn

bitwise_not

Tensor
bitwise_not(input: Tensor)
source

Element-wise bitwise NOT.

Inverts every bit of each integer entry. For boolean tensors this reduces to logical negation (logical_not).

Parameters

inputTensor
Input tensor. Must have integer or boolean dtype.

Returns

Tensor

Tensor with the same shape and dtype as input, with every bit flipped.

Notes

For a signed two's-complement integer x of width WW bits:

outi=xi=xi1(mod2W)\text{out}_i = \,\sim x_i = -x_i - 1 \pmod{2^{W}}

Not differentiable; gradients are dropped.

Examples

>>> import lucid
>>> x = lucid.tensor([0, 1, -1], dtype=lucid.int32)
>>> lucid.bitwise_not(x)
Tensor([-1, -2, 0])