fn

bitwise_right_shift

Tensor
bitwise_right_shift(input: Tensor, other: Tensor | Scalar)
source

Element-wise bitwise right shift.

Shifts the bits of input to the right by other positions. For signed integer dtypes the shift is arithmetic (sign-extending); for unsigned dtypes it is logical (zero-filling).

Parameters

inputTensor
Left operand. Must have integer dtype.
otherTensor or scalar
Number of positions to shift. Must be a non-negative integer.

Returns

Tensor

Shifted tensor with shape broadcast(input.shape, other.shape).

Notes

Mathematical definition (signed, with floor division):

outi=inputi/2otheri\text{out}_i = \lfloor \text{input}_i / 2^{\text{other}_i} \rfloor

Shifting by an amount greater than or equal to the dtype's bit width is undefined behaviour and should be avoided. Not differentiable.

Examples

>>> import lucid
>>> a = lucid.tensor([8, 16, 32], dtype=lucid.int32)
>>> lucid.bitwise_right_shift(a, 2)
Tensor([2, 4, 8])