Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

kornia.geometry.solvers (polynomial_solvers) docs (#2484)

Anandhu9e89dfb759d2
diff --git a/docs/source/geometry.rst b/docs/source/geometry.rst
index eb3163e28..d1aff9193 100644
--- a/docs/source/geometry.rst
+++ b/docs/source/geometry.rst
@@ -57,6 +57,7 @@ transforms, camera, conversions, linalg and depth. We next describe each of them
geometry.linalg
geometry.line
geometry.quaternion
+ geometry.solvers
geometry.subpix
geometry.transform
geometry.ransac
diff --git a/docs/source/geometry.solvers.rst b/docs/source/geometry.solvers.rst
new file mode 100644
index 000000000..bad03b22c
--- /dev/null
+++ b/docs/source/geometry.solvers.rst
@@ -0,0 +1,12 @@
+kornia.geometry.solvers
+=======================
+
+.. currentmodule:: kornia.geometry.solvers
+
+Module containing various geometrical solvers/optimizers.
+
+Polynomial Solvers
+------------------
+
+.. autofunction:: solve_quadratic
+.. autofunction:: solve_cubic
diff --git a/kornia/geometry/solvers/polynomial_solver.py b/kornia/geometry/solvers/polynomial_solver.py
index ca02709ac..4d4caee0f 100644
--- a/kornia/geometry/solvers/polynomial_solver.py
+++ b/kornia/geometry/solvers/polynomial_solver.py
@@ -11,13 +11,24 @@ from kornia.core.check import KORNIA_CHECK_SHAPE
def solve_quadratic(coeffs: Tensor) -> Tensor:
r"""Solve given quadratic equation.
- The function takes the coefficients of quadratic equation and returns the solutions.
+ The function takes the coefficients of quadratic equation and returns the real roots.
+
+ .. math:: coeffs[0]x^2 + coeffs[1]x + coeffs[2] = 0
Args:
coeffs : The coefficients of quadratic equation :`(B, 3)`
Returns:
- A tensor of shape `(B, 2)` containing the solutions to the quadratic equation.
+ A tensor of shape `(B, 2)` containing the real roots to the quadratic equation.
+
+ Example:
+ >>> coeffs = torch.tensor([[1., 4., 4.]])
+ >>> roots = solve_quadratic(coeffs)
+
+ .. note::
+ In cases where a quadratic polynomial has only one real root, the output will be in the format
+ [real_root, 0]. And for the complex roots should be represented as 0. This is done to maintain
+ a consistent output shape for all cases.
"""
KORNIA_CHECK_SHAPE(coeffs, ['B', '3'])
@@ -62,13 +73,24 @@ def solve_cubic(coeffs: Tensor) -> Tensor:
r"""Solve given cubic equation.
The function takes the coefficients of cubic equation and returns
- the solutions.
+ the real roots.
+
+ .. math:: coeffs[0]x^3 + coeffs[1]x^2 + coeffs[2]x + coeffs[3] = 0
Args:
coeffs : The coefficients cubic equation : `(B, 4)`
Returns:
- A tensor of shape `(B, 3)` containing the solutions to the cubic equation.
+ A tensor of shape `(B, 3)` containing the real roots to the cubic equation.
+
+ Example:
+ >>> coeffs = torch.tensor([[32., 3., -11., -6.]])
+ >>> roots = solve_cubic(coeffs)
+
+ .. note::
+ In cases where a cubic polynomial has only one or two real roots, the output for the non-real
+ roots should be represented as 0. Thus, the output for a single real root should be in the
+ format [real_root, 0, 0], and for two real roots, it should be [real_root_1, real_root_2, 0].
"""
KORNIA_CHECK_SHAPE(coeffs, ['B', '4'])