torch.Tensor.Tensor.logical_or_
In-place element-wise logical OR.
Computes the logical OR between two boolean tensors element-wise. Returns true when at least one input is true. Essential for combining alternative conditions in boolean operations.
Use Cases:
- Combining alternative conditions for mask creation
- Implementing OR logic for tensor filtering
- Merging multiple boolean conditions
- Broadcasting: Both tensors are broadcast to compatible shapes
- Boolean tensors: Both inputs must be boolean tensors
- In-place: Modifies this tensor directly and returns it for chaining
- Commutativity: OR is commutative: a OR b = b OR a
Parameters
otherTensor- The other tensor (will be broadcast if needed)
Returns
this– This tensor modified in-placeExamples
// Combine two boolean conditions with OR
const mask1 = torch.tensor([true, true, false, true]);
const mask2 = torch.tensor([true, false, false, true]);
mask1.logical_or_(mask2); // [true, true, false, true]
// Find values outside range [0, 5]
const x = torch.tensor([0, 2, 7, 3, 9]);
const outside = x.lt(0).logical_or(x.gt(5));
const extremes = x.masked_select(outside); // [7, 9]
// Union of two conditions
const batch = torch.randn(100, 50);
const isVerySmall = batch.lt(-2);
const isVeryLarge = batch.gt(2);
const extreme = isVerySmall.logical_or(isVeryLarge);See Also
- PyTorch tensor.logical_or_()
- logical_and_ - Element-wise logical AND
- logical_not_ - Element-wise logical NOT
- logical_xor_ - Element-wise logical XOR