From b591c8e38f53de2b02e95ada92e9b82b0b452480 Mon Sep 17 00:00:00 2001 From: Amrita kumari mishra Date: Wed, 22 Oct 2025 09:33:48 +0000 Subject: [PATCH 1/3] feat(docs): Add PyTorch logical_or term entry (closes #7786) --- .../terms/logical-or/logical-or.md | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 content/pytorch/concepts/tensor-operations/terms/logical-or/logical-or.md diff --git a/content/pytorch/concepts/tensor-operations/terms/logical-or/logical-or.md b/content/pytorch/concepts/tensor-operations/terms/logical-or/logical-or.md new file mode 100644 index 00000000000..d61c26eff45 --- /dev/null +++ b/content/pytorch/concepts/tensor-operations/terms/logical-or/logical-or.md @@ -0,0 +1,70 @@ +--- +Title: logical_or() +Description: Performs an element-wise logical OR operation between two tensors. +Subjects: PyTorch, Tensor Operations, Logical Operations +Tags: PyTorch, Tensor +--- + +The `logical_or()` operation performs an element-wise logical OR between two tensors. For each corresponding element pair, it returns _True_ if _either_ element is _True_, and _False_ only if _both_ elements are _False_. + +This operation can be used either as a function in the torch module or as a tensor method. + +## Syntax + +1. **Function form:** + + ```python + torch.logical_or(input, other, out=None) + ``` + +2. **Tensor method form:** + + ```python + input.logical_or(other, out=None) + ``` + +**Parameters:** + +- `input` (Tensor): The first tensor to compare. +- `other` (Tensor): The second tensor to compare. +- `out` (Tensor, optional): Tensor to store the output. + +## Codebyte Example + +```codebyte/python +import torch + +# Example 1: Using boolean tensors +tensor1 = torch.tensor([True, False, True, False]) +tensor2 = torch.tensor([True, True, False, False]) + +result = torch.logical_or(tensor1, tensor2) +print(f"Example 1 Result:\n{result}\n") +# Output: +# Example 1 Result: +# tensor([True, True, True, False]) + +# Example 2: Using integer tensors +# Non-zero values are treated as True, and 0 as False. +tensor_a = torch.tensor([1, 0, 0, 7]) +tensor_b = torch.tensor([0, 0, 3, 0]) + +result_b = tensor_a.logical_or(tensor_b) +print(f"Example 2 Result:\n{result_b}\n") +# Output: +# Example 2 Result: +# tensor([True, False, True, True]) + +# Example 3: Broadcasting +# A 1D tensor is broadcast to match the 2D tensor's shape. +tensor_2d = torch.tensor([[True, False, True], + [False, False, False]]) +tensor_1d = torch.tensor([True, False, False]) + +result_c = torch.logical_or(tensor_2d, tensor_1d) +print(f"Example 3 (Broadcasting) Result:\n{result_c}") +# Output: +# Example 3 (Broadcasting) Result: +# tensor([[ True, False, True], +# [ True, False, False]]) +``` From 899ea157536394547bd2c61e22e77717d39fff9b Mon Sep 17 00:00:00 2001 From: Amrita kumari mishra Date: Wed, 22 Oct 2025 10:11:16 +0000 Subject: [PATCH 2/3] fix(docs): update frontmatter keys to lowercase for logical_or entry --- .../tensor-operations/terms/logical-or/logical-or.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/logical-or/logical-or.md b/content/pytorch/concepts/tensor-operations/terms/logical-or/logical-or.md index d61c26eff45..7defc3b816d 100644 --- a/content/pytorch/concepts/tensor-operations/terms/logical-or/logical-or.md +++ b/content/pytorch/concepts/tensor-operations/terms/logical-or/logical-or.md @@ -1,8 +1,8 @@ --- -Title: logical_or() -Description: Performs an element-wise logical OR operation between two tensors. -Subjects: PyTorch, Tensor Operations, Logical Operations -Tags: PyTorch, Tensor +title: logical_or() +description: Performs an element-wise logical OR operation between two tensors. +subjects: PyTorch, Tensor Operations, Logical Operations +tags: PyTorch, Tensor --- The `logical_or()` operation performs an element-wise logical OR between two tensors. For each corresponding element pair, it returns _True_ if _either_ element is _True_, and _False_ only if _both_ elements are _False_. From 3247e6485d02cd53d39336549042cb64ec4cd165 Mon Sep 17 00:00:00 2001 From: Amrita kumari mishra Date: Wed, 22 Oct 2025 16:33:09 +0000 Subject: [PATCH 3/3] Added # Example section between Syntax and Codebyte Example in logical_or docs --- .../terms/logical-or/logical-or.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/content/pytorch/concepts/tensor-operations/terms/logical-or/logical-or.md b/content/pytorch/concepts/tensor-operations/terms/logical-or/logical-or.md index 7defc3b816d..b8abe1225ee 100644 --- a/content/pytorch/concepts/tensor-operations/terms/logical-or/logical-or.md +++ b/content/pytorch/concepts/tensor-operations/terms/logical-or/logical-or.md @@ -29,6 +29,24 @@ This operation can be used either as a function in the torch module or as a tens - `other` (Tensor): The second tensor to compare. - `out` (Tensor, optional): Tensor to store the output. +## Example + +```python +import torch + +# Example 1: Using boolean tensors +a = torch.tensor([True, False, True, False]) +b = torch.tensor([True, True, False, False]) +print(torch.logical_or(a, b)) +# Output: tensor([True, True, True, False]) + +# Example 2: Using integer tensors +x = torch.tensor([1, 0, 0, 7]) +y = torch.tensor([0, 0, 3, 0]) +print(x.logical_or(y)) +# Output: tensor([True, False, True, True]) +``` + ## Codebyte Example ```codebyte/python