From 9e3a5c698d88f1fd9e9d846045f9659824c2d20e Mon Sep 17 00:00:00 2001 From: Yuval Date: Mon, 27 Oct 2025 07:45:31 -0400 Subject: [PATCH 1/5] Add .i0() term entry for PyTorch Tensor Operations (Issue #7790) --- .../concepts/tensor-operations/terms/i0/i0.md | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 content/pytorch/concepts/tensor-operations/terms/i0/i0.md diff --git a/content/pytorch/concepts/tensor-operations/terms/i0/i0.md b/content/pytorch/concepts/tensor-operations/terms/i0/i0.md new file mode 100644 index 00000000000..984afe7d418 --- /dev/null +++ b/content/pytorch/concepts/tensor-operations/terms/i0/i0.md @@ -0,0 +1,93 @@ +--- +Title: '.i0()' +Description: 'Computes the modified Bessel function of the first kind of order zero.' +Subjects: + - 'AI' + - 'Data Science' + - 'Machine Learning' +Tags: + - 'AI' + - 'Deep Learning' + - 'Functions' + - 'Machine Learning' + - 'PyTorch' +CatalogContent: + - 'intro-to-py-torch-and-neural-networks' + - 'paths/computer-science' +--- + +In PyTorch, the `.i0()` method computes the modified Bessel function of the first kind of order zero (I₀). This function is commonly used in signal processing, physics simulations, and statistical distributions such as the von Mises distribution for circular data. + +## Syntax + +```py +torch.i0(input, *, out=None) +``` + +### Parameters + +- `input` (Tensor): The input tensor. + +### Keyword Arguments + +- `out` (Tensor, optional): The output tensor. + +### Return Value + +Returns a tensor containing the computed modified Bessel function values. The function computes I₀(x) for each element in the input tensor. + +## Example + +The following example demonstrates the use of `.i0()`: + +```py +import torch + +# Create input tensor +x = torch.tensor([0.0, 1.0, 2.0, 3.0, 4.0]) + +# Compute the modified Bessel function +result = torch.i0(x) + +print("Input values:", x) +print("I₀(x) values:", result) +``` + +The above code produces the following output: + +``` +Input values: tensor([0., 1., 2., 3., 4.]) +I₀(x) values: tensor([1.0000, 1.2661, 2.2796, 4.8808, 11.3019]) +``` + +## Codebyte Example + +The following codebyte demonstrates `.i0()` in an interactive example: + +```codebyte/python +import torch + +# Example: Computing Bessel function for signal processing +# Generate a range of values +x = torch.linspace(-3, 3, 7) + +# Compute I₀(x) +bessel_values = torch.i0(x) + +print("Input values:", x) +print("I₀(x) values:", bessel_values) + +# Show that I₀(0) = 1 +zero_input = torch.tensor([0.0]) +print("\nI₀(0) =", torch.i0(zero_input).item()) + +# Show symmetry: I₀(-x) = I₀(x) +positive = torch.tensor([2.0]) +negative = torch.tensor([-2.0]) +print("I₀(2) =", torch.i0(positive).item()) +print("I₀(-2) =", torch.i0(negative).item()) +``` + +``` + +``` From 40cf16dd4ba611bf7470fe407a56a5b6a2f0a523 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 27 Oct 2025 21:20:48 +0530 Subject: [PATCH 2/5] Improve documentation for the .i0() function Updated the description and syntax for the .i0() function, including parameters and return value. Added examples to illustrate its usage. --- .../concepts/tensor-operations/terms/i0/i0.md | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/i0/i0.md b/content/pytorch/concepts/tensor-operations/terms/i0/i0.md index 984afe7d418..9ed2ca59cd3 100644 --- a/content/pytorch/concepts/tensor-operations/terms/i0/i0.md +++ b/content/pytorch/concepts/tensor-operations/terms/i0/i0.md @@ -16,29 +16,32 @@ CatalogContent: - 'paths/computer-science' --- -In PyTorch, the `.i0()` method computes the modified Bessel function of the first kind of order zero (I₀). This function is commonly used in signal processing, physics simulations, and statistical distributions such as the von Mises distribution for circular data. +In PyTorch, the **`.i0()`** funcation (an alias of `torch.special.i0()`) computes the modified Bessel function of the first kind of order zero (I₀). This function is commonly used in signal processing, physics simulations, and statistical distributions such as the von Mises distribution for circular data. ## Syntax -```py +```pseudo torch.i0(input, *, out=None) ``` -### Parameters +Or, alternatively: -- `input` (Tensor): The input tensor. +```shell +torch.special.i0(input, *, out=None) +``` -### Keyword Arguments +**Parameters:** -- `out` (Tensor, optional): The output tensor. +- `input` (Tensor): The input tensor whose elements are the values at which to compute the modified Bessel function I₀. +- `out` (Tensor, optional): The output tensor to store the result. -### Return Value +**Return value:** -Returns a tensor containing the computed modified Bessel function values. The function computes I₀(x) for each element in the input tensor. +Returns a tensor containing the computed modified Bessel function of the first kind, order zero (I₀), for each element of the input tensor. ## Example -The following example demonstrates the use of `.i0()`: +In this example, `torch.i0()` calculates the modified Bessel function I₀ for each element in a 1D tensor: ```py import torch @@ -55,14 +58,14 @@ print("I₀(x) values:", result) The above code produces the following output: -``` +```shell Input values: tensor([0., 1., 2., 3., 4.]) I₀(x) values: tensor([1.0000, 1.2661, 2.2796, 4.8808, 11.3019]) ``` ## Codebyte Example -The following codebyte demonstrates `.i0()` in an interactive example: +In this interactive example, `torch.i0()` is used to compute I₀ values across a range of inputs and demonstrate key properties like I₀(0) = 1 and I₀(x) = I₀(−x): ```codebyte/python import torch @@ -87,7 +90,3 @@ negative = torch.tensor([-2.0]) print("I₀(2) =", torch.i0(positive).item()) print("I₀(-2) =", torch.i0(negative).item()) ``` - -``` - -``` From 24c255a3b7232c6ee6f141e43008c22808c29b7b Mon Sep 17 00:00:00 2001 From: Daksha Deep Date: Tue, 28 Oct 2025 11:24:17 +0530 Subject: [PATCH 3/5] using pseudo for syntax --- content/pytorch/concepts/tensor-operations/terms/i0/i0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/i0/i0.md b/content/pytorch/concepts/tensor-operations/terms/i0/i0.md index 9ed2ca59cd3..2abad91fbff 100644 --- a/content/pytorch/concepts/tensor-operations/terms/i0/i0.md +++ b/content/pytorch/concepts/tensor-operations/terms/i0/i0.md @@ -26,7 +26,7 @@ torch.i0(input, *, out=None) Or, alternatively: -```shell +```pseudo torch.special.i0(input, *, out=None) ``` From 32a3d42b01ee2fa022f6d4d327f2566f03d44f0f Mon Sep 17 00:00:00 2001 From: Daksha Deep Date: Tue, 28 Oct 2025 11:25:04 +0530 Subject: [PATCH 4/5] Fixing typo and other minor issues --- content/pytorch/concepts/tensor-operations/terms/i0/i0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/i0/i0.md b/content/pytorch/concepts/tensor-operations/terms/i0/i0.md index 2abad91fbff..210b842fb5c 100644 --- a/content/pytorch/concepts/tensor-operations/terms/i0/i0.md +++ b/content/pytorch/concepts/tensor-operations/terms/i0/i0.md @@ -16,7 +16,7 @@ CatalogContent: - 'paths/computer-science' --- -In PyTorch, the **`.i0()`** funcation (an alias of `torch.special.i0()`) computes the modified Bessel function of the first kind of order zero (I₀). This function is commonly used in signal processing, physics simulations, and statistical distributions such as the von Mises distribution for circular data. +In PyTorch, the **`.i0()`** function (an alias of `torch.special.i0()`) computes the modified Bessel function of the first kind of order zero (I₀). This function is commonly used in signal processing, physics simulations, and statistical distributions such as the von Mises distribution for circular data. ## Syntax From 4d0728999a00eb6b49fed04ef30d97c66f249c5d Mon Sep 17 00:00:00 2001 From: Daksha Deep Date: Tue, 28 Oct 2025 11:26:15 +0530 Subject: [PATCH 5/5] Removed the codebyte due to compiler error --- .../concepts/tensor-operations/terms/i0/i0.md | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/i0/i0.md b/content/pytorch/concepts/tensor-operations/terms/i0/i0.md index 210b842fb5c..c07a4521ca5 100644 --- a/content/pytorch/concepts/tensor-operations/terms/i0/i0.md +++ b/content/pytorch/concepts/tensor-operations/terms/i0/i0.md @@ -62,31 +62,3 @@ The above code produces the following output: Input values: tensor([0., 1., 2., 3., 4.]) I₀(x) values: tensor([1.0000, 1.2661, 2.2796, 4.8808, 11.3019]) ``` - -## Codebyte Example - -In this interactive example, `torch.i0()` is used to compute I₀ values across a range of inputs and demonstrate key properties like I₀(0) = 1 and I₀(x) = I₀(−x): - -```codebyte/python -import torch - -# Example: Computing Bessel function for signal processing -# Generate a range of values -x = torch.linspace(-3, 3, 7) - -# Compute I₀(x) -bessel_values = torch.i0(x) - -print("Input values:", x) -print("I₀(x) values:", bessel_values) - -# Show that I₀(0) = 1 -zero_input = torch.tensor([0.0]) -print("\nI₀(0) =", torch.i0(zero_input).item()) - -# Show symmetry: I₀(-x) = I₀(x) -positive = torch.tensor([2.0]) -negative = torch.tensor([-2.0]) -print("I₀(2) =", torch.i0(positive).item()) -print("I₀(-2) =", torch.i0(negative).item()) -```