torch.Tensor.Tensor.bitwise_or
Tensor.bitwise_or(other: number): Tensor<S, D, Dev>Tensor.bitwise_or(other: Tensor | number): Tensor<DynamicShape, D, Dev>Bitwise OR operation (element-wise binary OR).
Performs bitwise OR between corresponding elements of two integer tensors. Each bit position is OR-ed independently: result bit is 1 if either input bit is 1. Only works with integer dtypes (int8, int32, uint8, uint32).
Use Cases:
- Setting bit flags
- Combining bit masks
- Binary feature operations
- Signal merging
- Protocol/data encoding
- Integer only: Works only with int8, uint8, int32, uint32 dtypes.
- Element-wise: Each element is OR-ed independently.
- Broadcasting: Other broadcasts with self.
Parameters
othernumber- Integer tensor to OR with (broadcastable)
Returns
Tensor<S, D, Dev>– Integer tensor with bitwise OR result, same shapeExamples
// Basic bitwise OR
const a = torch.tensor([0b1100, 0b1010], { dtype: 'int32' });
const b = torch.tensor([0b1010, 0b0101], { dtype: 'int32' });
a.bitwise_or(b); // [0b1110, 0b1111] = [14, 15]
// Setting flags
const flags = torch.tensor([0b00000000], { dtype: 'uint8' });
const set_bits = torch.tensor([0b00010100], { dtype: 'uint8' });
flags.bitwise_or(set_bits); // [0b00010100] - bits 2 and 4 setSee Also
- PyTorch torch.bitwise_or()
- bitwise_and - Bitwise AND
- bitwise_xor - Bitwise XOR
- bitwise_not - Bitwise NOT