如何在 Pytorch 中使用 BitShift 运算符?

How to use the BitShift operator in Pytorch?

有没有人有如何在 Pytorch 中使用 BitShift 运算符的示例?

Bitwise shift operator performs element-wise operation.

它的工作方式与 , and numpy 中的工作方式相同,即将整数的位向左或向右移动。 <<>>分别表示左移和右移。

x = torch.tensor([16, 4, 1])
y = torch.tensor([1, 2, 3])
z = x << y
print(z)
tensor([32, 16,  8])

相当于16 << 1np.left_shift(16, 1))、4 << 21 << 3

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.

This operator supports multidirectional (i.e., Numpy-style) broadcasting.