megengine.functional.right_shift#

right_shift(x, y)[source]#

Element-wise right shift.

Shifts the bits of each element \(x_i\) of the input tensor \(x\) to the right according to the respective element \(y_i\) of the input tensor \(y\).

Note

The >> operator can be used as a shorthand for right_shift on Tensors.

Note

This operation must be an arithmetic shift (i.e., sign-propagating) and thus equivalent to floor division by a power of two.

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 right shift operation. The returned tensor must have the a data type determined by Type promotion rules.

Examples

>>> F.right_shift([2, 4, 8], 1)
Tensor([1 2 4], dtype=int32, device=xpux:0)

Element-wise left shift:

>>> x = Tensor([2, 8, 24])
>>> y = Tensor([1, 2, 3])
>>> F.right_shift(x, y)
Tensor([1 2 3], dtype=int32, device=xpux:0)

Broadcasting:

>>> F.right_shift([10, 20, 40], 2)
Tensor([ 2  5 10], dtype=int32, device=xpux:0)