From 18f83a258ebdba12be76e3b27223c85991f278c1 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Tue, 10 May 2022 13:53:14 +0800 Subject: [PATCH] docs(mge/functional): fix F.svd docstring GitOrigin-RevId: b84e5fdc46de51e68b93cf448af8a3e0d2e44c32 --- .../python/megengine/functional/math.py | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/imperative/python/megengine/functional/math.py b/imperative/python/megengine/functional/math.py index c61306390..8cf735623 100644 --- a/imperative/python/megengine/functional/math.py +++ b/imperative/python/megengine/functional/math.py @@ -656,19 +656,32 @@ def dot(inp1: Tensor, inp2: Tensor) -> Tensor: def svd(inp: Tensor, full_matrices=False, compute_uv=True) -> Tensor: - r"""Returns a singular value decomposition ``A = USVh`` of a matrix (or a stack of matrices) ``x`` , where ``U`` is a matrix (or a stack of matrices) with orthonormal columns, ``S`` is a vector of non-negative numbers (or stack of vectors), and ``Vh`` is a matrix (or a stack of matrices) with orthonormal rows. + r"""Computes the singular value decomposition of a matrix (or a stack of matrices) ``inp``. + + Let :math:`X` be the input matrix (or a stack of input matrices), the output should satisfies: + + .. math:: + X = U * diag(S) * Vh + + where ``U`` is a matrix (or stack of vectors) with orthonormal columns, ``S`` is a vector of + non-negative numbers (or stack of vectors), and ``Vh`` is a matrix (or a stack of matrices) + with orthonormal rows. Args: - x (Tensor): A input real tensor having the shape ``(..., M, N)`` with ``x.ndim >= 2`` . - full_matrices (bool, optional): If ``False`` , ``U`` and ``Vh`` have the shapes ``(..., M, K)`` and ``(..., K, N)`` , respectively, where ``K = min(M, N)`` . If ``True`` , the shapes are ``(..., M, M)`` and ``(..., N, N)`` , respectively. Default: ``False`` . + inp (Tensor): A input real tensor having the shape ``(..., M, N)`` with ``inp.ndim >= 2`` . + full_matrices (bool, optional): If ``False`` , ``U`` and ``Vh`` have the shapes ``(..., M, K)`` + and ``(..., K, N)`` , respectively, where ``K = min(M, N)`` . If ``True`` , the shapes + are ``(..., M, M)`` and ``(..., N, N)`` , respectively. Default: ``False`` . compute_uv (bool, optional): Whether or not to compute ``U`` and ``Vh`` in addition to ``S`` . Default: ``True`` . Note: * naive does not support ``full_matrices`` and ``compute_uv`` as ``True`` . Returns: - Returns a tuple ( ``U`` , ``S`` , ``Vh`` ), which are SVD factors ``U`` , ``S``, ``Vh`` of input matrix ``x``. ( ``U`` , ``Vh`` only returned when ``compute_uv`` is True). - ``U`` contains matrices orthonormal columns (i.e., the columns are left singular vectors). If ``full_matrices`` is ``True`` , the array must have shape ``(..., M, M)`` . If ``full_matrices`` is ``False`` , the array must have shape ``(..., M, K)`` , where ``K = min(M, N)`` . + Returns a tuple ( ``U`` , ``S`` , ``Vh`` ), which are SVD factors ``U`` , ``S``, ``Vh`` of input matrix ``inp``. + ( ``U`` , ``Vh`` only returned when ``compute_uv`` is True). ``U`` contains matrices orthonormal columns + (i.e., the columns are left singular vectors). If ``full_matrices`` is ``True`` , the array must have shape + ``(..., M, M)`` . If ``full_matrices`` is ``False`` , the array must have shape ``(..., M, K)`` , where ``K = min(M, N)`` . Examples: >>> import numpy as np -- GitLab