BitShift#

  • Domain: ai.onnx

  • Since version: 11

Bitwise shift operator performs element-wise operation. For each input element, if the attribute “direction” is “RIGHT”, this operator moves its binary representation toward the right side so that the input value is effectively decreased. If the attribute “direction” is “LEFT”, bits of binary representation moves toward the left side, which results the increase of its actual value. The input X is the tensor to be shifted and another input Y specifies the amounts of shifting. For example, if “direction” is “Right”, X is [1, 4], and S is [1, 1], the corresponding output Z would be [0, 2]. If “direction” is “LEFT” with X=[1, 2] and S=[1, 2], the corresponding output Y would be [2, 8].

Because this operator supports Numpy-style broadcasting, X’s and Y’s shapes are not necessarily identical. This operator supports multidirectional (i.e., Numpy-style) broadcasting; for more details please check the doc.

Inputs

  • X (T): First operand, input to be shifted.

  • Y (T): Second operand, amounts of shift.

Outputs

  • Z (T): Output tensor

Attributes

  • direction (string): Direction of moving bits. It can be either “RIGHT” (for right shift) or “LEFT” (for left shift).

Type Constraints

  • T: Constrain input and output types to integer tensors. Allowed types: tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8).

Examples#

test_bitshift_left_uint16

Node:
  BitShift(x, y) -> (z)
  Attributes:
    direction = "LEFT"
Inputs:
  x: shape=(3,), dtype=uint16
    [16,  4,  1]
  y: shape=(3,), dtype=uint16
    [1, 2, 3]

Outputs:
  z: shape=(3,), dtype=uint16
    [32, 16,  8]

test_bitshift_left_uint32

Node:
  BitShift(x, y) -> (z)
  Attributes:
    direction = "LEFT"
Inputs:
  x: shape=(3,), dtype=uint32
    [16,  4,  1]
  y: shape=(3,), dtype=uint32
    [1, 2, 3]

Outputs:
  z: shape=(3,), dtype=uint32
    [32, 16,  8]

test_bitshift_left_uint64

Node:
  BitShift(x, y) -> (z)
  Attributes:
    direction = "LEFT"
Inputs:
  x: shape=(3,), dtype=uint64
    [16,  4,  1]
  y: shape=(3,), dtype=uint64
    [1, 2, 3]

Outputs:
  z: shape=(3,), dtype=uint64
    [32, 16,  8]

test_bitshift_left_uint8

Node:
  BitShift(x, y) -> (z)
  Attributes:
    direction = "LEFT"
Inputs:
  x: shape=(3,), dtype=uint8
    [16,  4,  1]
  y: shape=(3,), dtype=uint8
    [1, 2, 3]

Outputs:
  z: shape=(3,), dtype=uint8
    [32, 16,  8]

test_bitshift_right_uint16

Node:
  BitShift(x, y) -> (z)
  Attributes:
    direction = "RIGHT"
Inputs:
  x: shape=(3,), dtype=uint16
    [16,  4,  1]
  y: shape=(3,), dtype=uint16
    [1, 2, 3]

Outputs:
  z: shape=(3,), dtype=uint16
    [8, 1, 0]

test_bitshift_right_uint32

Node:
  BitShift(x, y) -> (z)
  Attributes:
    direction = "RIGHT"
Inputs:
  x: shape=(3,), dtype=uint32
    [16,  4,  1]
  y: shape=(3,), dtype=uint32
    [1, 2, 3]

Outputs:
  z: shape=(3,), dtype=uint32
    [8, 1, 0]

test_bitshift_right_uint64

Node:
  BitShift(x, y) -> (z)
  Attributes:
    direction = "RIGHT"
Inputs:
  x: shape=(3,), dtype=uint64
    [16,  4,  1]
  y: shape=(3,), dtype=uint64
    [1, 2, 3]

Outputs:
  z: shape=(3,), dtype=uint64
    [8, 1, 0]

test_bitshift_right_uint8

Node:
  BitShift(x, y) -> (z)
  Attributes:
    direction = "RIGHT"
Inputs:
  x: shape=(3,), dtype=uint8
    [16,  4,  1]
  y: shape=(3,), dtype=uint8
    [1, 2, 3]

Outputs:
  z: shape=(3,), dtype=uint8
    [8, 1, 0]

test_cc_bitshift_left_u8

Node:
  BitShift(x, y) -> (z)
  Attributes:
    direction = "LEFT"
Inputs:
  x: shape=(2,), dtype=uint8
    [1, 2]
  y: shape=(2,), dtype=uint8
    [1, 2]

Outputs:
  z: shape=(2,), dtype=uint8
    [2, 8]

test_cc_bitshift_right_u8

Node:
  BitShift(x, y) -> (z)
  Attributes:
    direction = "RIGHT"
Inputs:
  x: shape=(2,), dtype=uint8
    [1, 4]
  y: shape=(2,), dtype=uint8
    [1, 1]

Outputs:
  z: shape=(2,), dtype=uint8
    [0, 2]