megengine.functional.left_shift

left_shift(x, y)[源代码]

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\).

注解

The << operator can be used as a shorthand for left_shift on Tensors.

参数
  • x – first input tensor. Should have an integer data type.

  • y – second input tensor. Must be compatible with \(x\) (see 广播机制与规则 ). Should have an integer data type. Each element must be greater than or equal to 0.

返回

a tensor containing the result of the element-wise left shift operation. The returned tensor must have the a data type determined by 类型提升规则.

实际案例

>>> 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)