fn

bitwise_left_shift

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

Element-wise bitwise left shift.

Shifts the bits of input to the left by other positions, filling vacated low-order bits with zero. Equivalent to integer multiplication by 2other2^{\text{other}} modulo the dtype width.

Parameters

inputTensor
Left operand. Must have integer dtype.
otherTensor or scalar
Number of positions to shift. Must be a non-negative integer; shifting by more than the bit-width of input is undefined and clamped or wrapped depending on the underlying integer dtype.

Returns

Tensor

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

Notes

Mathematical definition (modulo the dtype's bit width WW):

outi=(inputi2otheri)mod2W\text{out}_i = (\text{input}_i \cdot 2^{\text{other}_i}) \bmod 2^{W}

High-order bits are lost on overflow. Not differentiable.

Examples

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