You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/10/30 04:21:32 UTC

[GitHub] [incubator-mxnet] xidulu commented on a change in pull request #16667: [NumPy] Add NumPy support for Cholesky decomposition

xidulu commented on a change in pull request #16667: [NumPy] Add NumPy support for Cholesky decomposition
URL: https://github.com/apache/incubator-mxnet/pull/16667#discussion_r340425892
 
 

 ##########
 File path: python/mxnet/symbol/numpy/linalg.py
 ##########
 @@ -128,3 +128,65 @@ def svd(a):
      - Does not support complex input.
     """
     return _npi.svd(a)
+
+
+def cholesky(a):
+    r"""
+    Cholesky decomposition.
+
+    Return the Cholesky decomposition, `L * L.T`, of the square matrix `a`,
+    where `L` is lower-triangular and .T is the transpose operator. `a` must be
+    symmetric and positive-definite. Only `L` is actually returned. Complex-valued
+    input is currently not supported.
+
+    Parameters
+    ----------
+    a : (..., M, M) ndarray
+        Symmetric, positive-definite input matrix.
+
+    Returns
+    -------
+    L : (..., M, M) ndarray
+        Lower-triangular Cholesky factor of `a`.
+
+    Raises
+    ------
+    MXNetError
+        If the dcomposition fails, for example, if `a` is not positive-definite.
+
+    Notes
+    -----
+    Broadcasting rules apply.
+
+    The Cholesky decomposition is often used as a fast way of solving
+
+    .. math:: A \mathbf{x} = \mathbf{b}
+
+    (when `A` is both symmetric and positive-definite).
+
+    First, we solve for :math:`\mathbf{y}` in
+
+    .. math:: L \mathbf{y} = \mathbf{b},
+
+    and then for :math:`\mathbf{x}` in
+
+    .. math:: L.T \mathbf{x} = \mathbf{y}.
+
+    Examples
+    --------
+    >>> A = np.array([[16, 4], [4, 10]])
+    >>> A
+    array([[16.,  4.],
+           [ 4., 10.]])
+    >>> L = np.linalg.cholesky(A)
+    >>> L
+    array([[4., 0.],
+           [1., 3.]])
+    >>> np.dot(L, L.T)
+    array([[16.,  4.],
+           [ 4., 10.]])
+    """
+    # if empty, behave the same as numpy
+    if len(a.as_nd_ndarray()) == 0:
 
 Review comment:
   You'd better cover the zero-size case in the unit tests, in both symbolic and imperative mode.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services