From deb72b536fcc6ac5ca28beee3fd3fbf5d26ceb6e Mon Sep 17 00:00:00 2001 From: Neema Date: Tue, 6 May 2025 12:02:03 +0300 Subject: [PATCH 1/3] Added file on bitwise_xor --- .../terms/bitwise-xor/bitwise-xor.md | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 content/pytorch/concepts/tensor-operations/terms/bitwise-xor/bitwise-xor.md diff --git a/content/pytorch/concepts/tensor-operations/terms/bitwise-xor/bitwise-xor.md b/content/pytorch/concepts/tensor-operations/terms/bitwise-xor/bitwise-xor.md new file mode 100644 index 00000000000..a03203a0653 --- /dev/null +++ b/content/pytorch/concepts/tensor-operations/terms/bitwise-xor/bitwise-xor.md @@ -0,0 +1,56 @@ +--- +Title: '.bitwise_xor()' +Description: 'Computes the bitwise XOR value of the inputs' +Subjects: + - 'Computer Science' + - 'Data Science' + - 'Machine Learning' +Tags: + - 'Linear Algebra' + - 'Machine Learning' + - 'Pytorch' +CatalogContent: + - 'learn-python-3' + - 'paths/computer-science' + - 'paths/data-science' + - 'paths/data-science-foundations' +--- + +The **`.bitwise_xor()`** is used to calculate the bitwise XOR value of the inputs. The inputs should be either of boolean or of integer value. In the case of integral inputs, the value are converted to their binary value and then computed. + +## Syntax + +```pseudo +torch.bitwise_xor(input, other, *, out=None) +``` + +Parameters: + +-`input`: The first input tensor -`other`: The second input tensor or a single number -`out`: The output tensor + +## Example + +The following example demonstrates how to perform bitwise XOR on a tensor: + +```py +import torch + +#create two tensors +a = torch.tensor([-1, 1, 0, -3], dtype=torch.int8) +b = torch.tensor([7, 1, -5, 3], dtype=torch.int8) + +#apply bitwise_xor on two tensors +c = torch.bitwise_xor(a,b) +print("c =",c) + +#apply bitwise_xor on a tensor and number +d = torch.bitwise_xor(b, -9) +print("d =",d) +``` + +This produces the following output: + +```shell +c = tensor([-8, 0, -5, -2], dtype=torch.int8) +d = tensor([-16, -10, 12, -12], dtype=torch.int8) +``` From 1e6c7e4146297caa0111130cf9931b9b838403ed Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Thu, 8 May 2025 22:23:49 +0530 Subject: [PATCH 2/3] minor fixes --- .../terms/bitwise-xor/bitwise-xor.md | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/bitwise-xor/bitwise-xor.md b/content/pytorch/concepts/tensor-operations/terms/bitwise-xor/bitwise-xor.md index a03203a0653..c97264c4459 100644 --- a/content/pytorch/concepts/tensor-operations/terms/bitwise-xor/bitwise-xor.md +++ b/content/pytorch/concepts/tensor-operations/terms/bitwise-xor/bitwise-xor.md @@ -1,6 +1,6 @@ --- Title: '.bitwise_xor()' -Description: 'Computes the bitwise XOR value of the inputs' +Description: 'Computes the bitwise XOR value of the inputs.' Subjects: - 'Computer Science' - 'Data Science' @@ -12,11 +12,9 @@ Tags: CatalogContent: - 'learn-python-3' - 'paths/computer-science' - - 'paths/data-science' - - 'paths/data-science-foundations' --- -The **`.bitwise_xor()`** is used to calculate the bitwise XOR value of the inputs. The inputs should be either of boolean or of integer value. In the case of integral inputs, the value are converted to their binary value and then computed. +The **`.bitwise_xor()`** is used to calculate the bitwise XOR value of the inputs. The inputs should be either of boolean or of integer value. In the case of integral inputs, the values are converted to their binary value and then computed. ## Syntax @@ -24,26 +22,32 @@ The **`.bitwise_xor()`** is used to calculate the bitwise XOR value of the input torch.bitwise_xor(input, other, *, out=None) ``` -Parameters: +**Parameters:** --`input`: The first input tensor -`other`: The second input tensor or a single number -`out`: The output tensor +-`input`: The first input tensor with boolean or integer values to apply XOR on. +-`other`: The second input tensor or a single number. +-`out`: The output tensor to store the result. + +**Return value:** + +- A tensor containing the result of the element-wise bitwise XOR operation. The output tensor has the same shape as the broadcasted shape of `input` and `other`. ## Example -The following example demonstrates how to perform bitwise XOR on a tensor: +The following example shows how to perform bitwise XOR on a tensor: ```py import torch -#create two tensors +# Create two tensors a = torch.tensor([-1, 1, 0, -3], dtype=torch.int8) b = torch.tensor([7, 1, -5, 3], dtype=torch.int8) -#apply bitwise_xor on two tensors +# Apply bitwise_xor on two tensors c = torch.bitwise_xor(a,b) print("c =",c) -#apply bitwise_xor on a tensor and number +# Apply bitwise_xor on a tensor and number d = torch.bitwise_xor(b, -9) print("d =",d) ``` From fd6ad840c894570e2fb51c675f0707df68a180ae Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Thu, 8 May 2025 22:24:21 +0530 Subject: [PATCH 3/3] Update bitwise-xor.md --- .../tensor-operations/terms/bitwise-xor/bitwise-xor.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/bitwise-xor/bitwise-xor.md b/content/pytorch/concepts/tensor-operations/terms/bitwise-xor/bitwise-xor.md index c97264c4459..392e34a42e1 100644 --- a/content/pytorch/concepts/tensor-operations/terms/bitwise-xor/bitwise-xor.md +++ b/content/pytorch/concepts/tensor-operations/terms/bitwise-xor/bitwise-xor.md @@ -24,9 +24,9 @@ torch.bitwise_xor(input, other, *, out=None) **Parameters:** --`input`: The first input tensor with boolean or integer values to apply XOR on. --`other`: The second input tensor or a single number. --`out`: The output tensor to store the result. +- `input`: The first input tensor with boolean or integer values to apply XOR on. +- `other`: The second input tensor or a single number. +- `out`: The output tensor to store the result. **Return value:**