From 966822c61e6a3684c389e53682bb8b556abf552d Mon Sep 17 00:00:00 2001 From: Vishakha Agrawal <119448495+vishakha1411@users.noreply.github.com> Date: Sun, 11 Jan 2026 03:15:05 +0530 Subject: [PATCH 1/5] Add documentation for PyTorch .sinh() function #8139 Added documentation for the .sinh() function in PyTorch, including its syntax, parameters, return value, and examples. Issue #8139 --- .../tensor-operations/terms/sinh/sinh.md | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 content/pytorch/concepts/tensor-operations/terms/sinh/sinh.md diff --git a/content/pytorch/concepts/tensor-operations/terms/sinh/sinh.md b/content/pytorch/concepts/tensor-operations/terms/sinh/sinh.md new file mode 100644 index 00000000000..3aa87e253d7 --- /dev/null +++ b/content/pytorch/concepts/tensor-operations/terms/sinh/sinh.md @@ -0,0 +1,118 @@ +--- +Title: '.sinh()' +Description: 'Computes the hyperbolic sine of each element in a PyTorch tensor.' +Subjects: + - 'Machine Learning' + - 'Data Science' +Tags: + - 'PyTorch' + - 'Deep Learning' + - 'Machine Learning' + - 'Tensors' +CatalogContent: + - 'intro-to-py-torch-and-neural-networks' + - 'paths/computer-science' +--- + +The **`.sinh()`** function in PyTorch computes the hyperbolic sine of each element in the input tensor. This operation applies the mathematical function $\sinh(x) = \frac{e^x - e^{-x}}{2}$ element-wise to all values in the tensor. + +The hyperbolic sine function is commonly used in neural network activation functions, numerical methods, and scientific computing applications involving hyperbolic trigonometric transformations. + +## Syntax + +```pseudo +torch.sinh(input, *, out=None) → Tensor +``` + +**Parameters:** + +- `input`: The input tensor containing elements for which the hyperbolic sine will be computed. +- `out` (optional): A tensor to store the output. If provided, the result is written to this tensor. + +**Return value:** + +Returns a new tensor where each element is the hyperbolic sine of the corresponding element in the input tensor. + +## Example 1: Single Element Tensor + +This example demonstrates computing the hyperbolic sine of a single-element tensor: + +```py +import torch + +# Create a single-element tensor +x = torch.tensor([2.0]) + +# Compute the hyperbolic sine +result = torch.sinh(x) + +print("Input:", x) +print("sinh(2.0):", result) +``` + +This produces the following output: + +``` +Input: tensor([2.]) +sinh(2.0): tensor([3.6269]) +``` + +## Example 2: 1D Array + +This example shows how to compute the hyperbolic sine of a 1D tensor: + +```py +import torch + +# Create a 1D tensor with various values +x = torch.tensor([0.0, 1.0, -1.0, 2.0, -2.0]) + +# Compute the hyperbolic sine +result = torch.sinh(x) + +print("Input tensor:", x) +print("Hyperbolic sine:", result) +``` + +This produces the following output: + +``` +Input tensor: tensor([ 0., 1., -1., 2., -2.]) +Hyperbolic sine: tensor([ 0.0000, 1.1752, -1.1752, 3.6269, -3.6269]) +``` + +Note that the hyperbolic sine function is antisymmetric, meaning $\sinh(-x) = -\sinh(x)$, which is why `sinh(1.0)` and `sinh(-1.0)` have opposite signs but equal magnitudes. + +## Example 3: Multi-Dimensional Array + +This example demonstrates computing the hyperbolic sine of a 2D tensor: + +```py +import torch + +# Create a 2D tensor (2x3 matrix) +x = torch.tensor([[0.0, 0.5, 1.0], + [1.5, 2.0, 2.5]]) + +# Compute the hyperbolic sine +result = torch.sinh(x) + +print("Input tensor:") +print(x) +print("\nHyperbolic sine:") +print(result) +``` + +This produces the following output: + +``` +Input tensor: +tensor([[0.0000, 0.5000, 1.0000], + [1.5000, 2.0000, 2.5000]]) + +Hyperbolic sine: +tensor([[ 0.0000, 0.5211, 1.1752], + [ 2.1293, 3.6269, 6.0502]]) +``` + +The `.sinh()` function preserves the shape of the input tensor, applying the hyperbolic sine operation element-wise to each value in the multi-dimensional array. From 347c8b0741c3e2c2553620fe68f3486455afa893 Mon Sep 17 00:00:00 2001 From: Vishakha Agrawal <119448495+vishakha1411@users.noreply.github.com> Date: Sun, 11 Jan 2026 03:28:01 +0530 Subject: [PATCH 2/5] [Tern Entry] Add .sqrt() function documentation Add documentation for the .sqrt() function in PyTorch, including syntax, parameters, return value, and examples for single-element and 1D tensors. #8141 --- .../tensor-operations/terms/sqrt/sqrt.md | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 content/pytorch/concepts/tensor-operations/terms/sqrt/sqrt.md diff --git a/content/pytorch/concepts/tensor-operations/terms/sqrt/sqrt.md b/content/pytorch/concepts/tensor-operations/terms/sqrt/sqrt.md new file mode 100644 index 00000000000..4c477bbe3d5 --- /dev/null +++ b/content/pytorch/concepts/tensor-operations/terms/sqrt/sqrt.md @@ -0,0 +1,84 @@ +--- +Title: '.sqrt()' +Description: 'Computes the square root of each element in a PyTorch tensor.' +Subjects: + - 'Machine Learning' + - 'Data Science' +Tags: + - 'PyTorch' + - 'Deep Learning' + - 'Machine Learning' + - 'Tensors' +CatalogContent: + - 'intro-to-py-torch-and-neural-networks' + - 'paths/computer-science' +--- + +The **`.sqrt()`** function in PyTorch computes the square root of each element in the input tensor. This operation applies the mathematical function $\sqrt{x}$ element-wise to all values in the tensor. + +The square root function is commonly used in neural networks for normalization techniques, distance calculations (such as Euclidean distance), standard deviation computations, and various mathematical transformations in deep learning applications. + +## Syntax + +```pseudo +torch.sqrt(input, *, out=None) → Tensor +``` + +**Parameters:** + +- `input`: The input tensor containing non-negative elements for which the square root will be computed. +- `out` (optional): A tensor to store the output. If provided, the result is written to this tensor. + +**Return value:** + +Returns a new tensor where each element is the square root of the corresponding element in the input tensor. + +## Example 1: Single Element Tensor + +This example demonstrates computing the square root of a single-element tensor: + +```py +import torch + +# Create a single-element tensor +x = torch.tensor([16.0]) + +# Compute the square root +result = torch.sqrt(x) + +print("Input:", x) +print("sqrt(16.0):", result) +``` + +This produces the following output: + +``` +Input: tensor([16.]) +sqrt(16.0): tensor([4.]) +``` + +## Example 2: 1D Array + +This example shows how to compute the square root of a 1D tensor: + +```py +import torch + +# Create a 1D tensor with various values +x = torch.tensor([0.0, 1.0, 4.0, 9.0, 16.0, 25.0]) + +# Compute the square root +result = torch.sqrt(x) + +print("Input tensor:", x) +print("Square root:", result) +``` + +This produces the following output: + +``` +Input tensor: tensor([ 0., 1., 4., 9., 16., 25.]) +Square root: tensor([0., 1., 2., 3., 4., 5.]) +``` + +Note that $\sqrt{0} = 0$ and the square root function is only defined for non-negative real numbers. Attempting to compute the square root of negative numbers will result in `nan` (not a number) values. From a99ca3aa9aaa1831d11584487235e29fa421994d Mon Sep 17 00:00:00 2001 From: Vishakha Agrawal <119448495+vishakha1411@users.noreply.github.com> Date: Mon, 12 Jan 2026 18:41:41 +0530 Subject: [PATCH 3/5] Delete content/pytorch/concepts/tensor-operations/terms/sqrt directory --- .../tensor-operations/terms/sqrt/sqrt.md | 84 ------------------- 1 file changed, 84 deletions(-) delete mode 100644 content/pytorch/concepts/tensor-operations/terms/sqrt/sqrt.md diff --git a/content/pytorch/concepts/tensor-operations/terms/sqrt/sqrt.md b/content/pytorch/concepts/tensor-operations/terms/sqrt/sqrt.md deleted file mode 100644 index 4c477bbe3d5..00000000000 --- a/content/pytorch/concepts/tensor-operations/terms/sqrt/sqrt.md +++ /dev/null @@ -1,84 +0,0 @@ ---- -Title: '.sqrt()' -Description: 'Computes the square root of each element in a PyTorch tensor.' -Subjects: - - 'Machine Learning' - - 'Data Science' -Tags: - - 'PyTorch' - - 'Deep Learning' - - 'Machine Learning' - - 'Tensors' -CatalogContent: - - 'intro-to-py-torch-and-neural-networks' - - 'paths/computer-science' ---- - -The **`.sqrt()`** function in PyTorch computes the square root of each element in the input tensor. This operation applies the mathematical function $\sqrt{x}$ element-wise to all values in the tensor. - -The square root function is commonly used in neural networks for normalization techniques, distance calculations (such as Euclidean distance), standard deviation computations, and various mathematical transformations in deep learning applications. - -## Syntax - -```pseudo -torch.sqrt(input, *, out=None) → Tensor -``` - -**Parameters:** - -- `input`: The input tensor containing non-negative elements for which the square root will be computed. -- `out` (optional): A tensor to store the output. If provided, the result is written to this tensor. - -**Return value:** - -Returns a new tensor where each element is the square root of the corresponding element in the input tensor. - -## Example 1: Single Element Tensor - -This example demonstrates computing the square root of a single-element tensor: - -```py -import torch - -# Create a single-element tensor -x = torch.tensor([16.0]) - -# Compute the square root -result = torch.sqrt(x) - -print("Input:", x) -print("sqrt(16.0):", result) -``` - -This produces the following output: - -``` -Input: tensor([16.]) -sqrt(16.0): tensor([4.]) -``` - -## Example 2: 1D Array - -This example shows how to compute the square root of a 1D tensor: - -```py -import torch - -# Create a 1D tensor with various values -x = torch.tensor([0.0, 1.0, 4.0, 9.0, 16.0, 25.0]) - -# Compute the square root -result = torch.sqrt(x) - -print("Input tensor:", x) -print("Square root:", result) -``` - -This produces the following output: - -``` -Input tensor: tensor([ 0., 1., 4., 9., 16., 25.]) -Square root: tensor([0., 1., 2., 3., 4., 5.]) -``` - -Note that $\sqrt{0} = 0$ and the square root function is only defined for non-negative real numbers. Attempting to compute the square root of negative numbers will result in `nan` (not a number) values. From 4c53f221236f2c9125abef9455c06f8a7d82930f Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Tue, 13 Jan 2026 12:12:58 +0530 Subject: [PATCH 4/5] Enhance .sinh() documentation with examples and details Updated the description and examples for the .sinh() function, including clarifications on its usage and properties. --- .../tensor-operations/terms/sinh/sinh.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/sinh/sinh.md b/content/pytorch/concepts/tensor-operations/terms/sinh/sinh.md index 3aa87e253d7..966f9a88733 100644 --- a/content/pytorch/concepts/tensor-operations/terms/sinh/sinh.md +++ b/content/pytorch/concepts/tensor-operations/terms/sinh/sinh.md @@ -2,21 +2,21 @@ Title: '.sinh()' Description: 'Computes the hyperbolic sine of each element in a PyTorch tensor.' Subjects: - - 'Machine Learning' - 'Data Science' + - 'Machine Learning' Tags: - - 'PyTorch' - 'Deep Learning' - 'Machine Learning' + - 'PyTorch' - 'Tensors' CatalogContent: - 'intro-to-py-torch-and-neural-networks' - 'paths/computer-science' --- -The **`.sinh()`** function in PyTorch computes the hyperbolic sine of each element in the input tensor. This operation applies the mathematical function $\sinh(x) = \frac{e^x - e^{-x}}{2}$ element-wise to all values in the tensor. +The **`.sinh()`** function in PyTorch computes the hyperbolic sine of each element in the input [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors). This operation applies the mathematical function $\sinh(x) = \frac{e^x - e^{-x}}{2}$ element-wise to all values in the tensor. -The hyperbolic sine function is commonly used in neural network activation functions, numerical methods, and scientific computing applications involving hyperbolic trigonometric transformations. +The hyperbolic sine function is commonly used in numerical methods, scientific computing, and some experimental neural network architectures involving hyperbolic functions. ## Syntax @@ -52,7 +52,7 @@ print("sinh(2.0):", result) This produces the following output: -``` +```shell Input: tensor([2.]) sinh(2.0): tensor([3.6269]) ``` @@ -76,12 +76,12 @@ print("Hyperbolic sine:", result) This produces the following output: -``` +```shell Input tensor: tensor([ 0., 1., -1., 2., -2.]) Hyperbolic sine: tensor([ 0.0000, 1.1752, -1.1752, 3.6269, -3.6269]) ``` -Note that the hyperbolic sine function is antisymmetric, meaning $\sinh(-x) = -\sinh(x)$, which is why `sinh(1.0)` and `sinh(-1.0)` have opposite signs but equal magnitudes. +> **Note:** The hyperbolic sine function is antisymmetric, meaning $\sinh(-x) = -\sinh(x)$, which is why `sinh(1.0)` and `sinh(-1.0)` have opposite signs but equal magnitudes. ## Example 3: Multi-Dimensional Array @@ -105,7 +105,7 @@ print(result) This produces the following output: -``` +```shell Input tensor: tensor([[0.0000, 0.5000, 1.0000], [1.5000, 2.0000, 2.5000]]) From 6089eb43e868aff673c77d6799ed628b30c115e1 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Tue, 13 Jan 2026 12:20:23 +0530 Subject: [PATCH 5/5] Revise sinh.md with improved examples and tags Updated examples and tags for sinh function documentation. --- .../pytorch/concepts/tensor-operations/terms/sinh/sinh.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/sinh/sinh.md b/content/pytorch/concepts/tensor-operations/terms/sinh/sinh.md index 966f9a88733..725bfa36276 100644 --- a/content/pytorch/concepts/tensor-operations/terms/sinh/sinh.md +++ b/content/pytorch/concepts/tensor-operations/terms/sinh/sinh.md @@ -8,7 +8,7 @@ Tags: - 'Deep Learning' - 'Machine Learning' - 'PyTorch' - - 'Tensors' + - 'Tensor' CatalogContent: - 'intro-to-py-torch-and-neural-networks' - 'paths/computer-science' @@ -33,7 +33,7 @@ torch.sinh(input, *, out=None) → Tensor Returns a new tensor where each element is the hyperbolic sine of the corresponding element in the input tensor. -## Example 1: Single Element Tensor +## Example 1: Computing the Hyperbolic Sine of a Scalar Tensor This example demonstrates computing the hyperbolic sine of a single-element tensor: @@ -57,7 +57,7 @@ Input: tensor([2.]) sinh(2.0): tensor([3.6269]) ``` -## Example 2: 1D Array +## Example 2: Applying `.sinh()` to a One-Dimensional Tensor This example shows how to compute the hyperbolic sine of a 1D tensor: @@ -83,7 +83,7 @@ Hyperbolic sine: tensor([ 0.0000, 1.1752, -1.1752, 3.6269, -3.6269]) > **Note:** The hyperbolic sine function is antisymmetric, meaning $\sinh(-x) = -\sinh(x)$, which is why `sinh(1.0)` and `sinh(-1.0)` have opposite signs but equal magnitudes. -## Example 3: Multi-Dimensional Array +## Example 3: Applying `.sinh()` to a Multi-Dimensional Tensor This example demonstrates computing the hyperbolic sine of a 2D tensor: