megengine.functional.left_shift¶
- left_shift(x, y)[source]¶
Element-wise left shift.
Shifts the bits of each element \(x_i\) of the input tensor \(x\) to the left by appending \(y_i\) (i.e., the respective element in the input tesnor \(y\)) zeros to the right of \(x_i\).
Note
The
<<
operator can be used as a shorthand forleft_shift
on Tensors.- Parameters
x – first input tensor. Should have an integer data type.
y – second input tensor. Must be compatible with \(x\) (see Broadcasting mechanism and rules ). Should have an integer data type. Each element must be greater than or equal to
0
.
- Returns
a tensor containing the result of the element-wise left shift operation. The returned tensor must have the a data type determined by Type promotion rules.
Examples
>>> F.left_shift([1, 2, 3], 1) Tensor([2 4 6], dtype=int32, device=xpux:0)
Element-wise left shift:
>>> x = Tensor([1, 2, 3]) >>> y = Tensor([1, 2, 3]) >>> F.left_shift(x, y) Tensor([ 2 8 24], dtype=int32, device=xpux:0)
Broadcasting:
>>> F.left_shift(5, [1, 2, 3]) Tensor([10 20 40], dtype=int32, device=xpux:0)