docstr: Cholesky decomposition of a symmetric positive-definite matrix `A`.
  Returns a lower triangular matrix `L` such that `A = L \times L^T`.
  More generally, for a complex Hermitian positive-definite matrix,
  a Cholesky decomposition satisfying `A = L \times L^H` is returned.
  
  The Cholesky decomposition can be used to solve linear equation
  systems twice as efficiently as LU decomposition, or to
  test whether `A` is positive-definite.
  
  The optional parameter ``tol`` determines the tolerance for
  verifying positive-definiteness.
  
  **Examples**
  
  Cholesky decomposition of a positive-definite symmetric matrix::
  
      >>> from mpmath import *
      >>> mp.dps = 25; mp.pretty = True
      >>> A = eye(3) + hilbert(3)
      >>> nprint(A)
      [     2.0      0.5  0.333333]
      [     0.5  1.33333      0.25]
      [0.333333     0.25       1.2]
      >>> L = cholesky(A)
      >>> nprint(L)
      [ 1.41421      0.0      0.0]
      [0.353553  1.09924      0.0]
      [0.235702  0.15162  1.05899]
      >>> chop(A - L*L.T)
      [0.0  0.0  0.0]
      [0.0  0.0  0.0]
      [0.0  0.0  0.0]
  
  Cholesky decomposition of a Hermitian matrix::
  
      >>> A = eye(3) + matrix([[0,0.25j,-0.5j],[-0.25j,0,0],[0.5j,0,0]])
      >>> L = cholesky(A)
      >>> nprint(L)
      [          1.0                0.0                0.0]
      [(0.0 - 0.25j)  (0.968246 + 0.0j)                0.0]
      [ (0.0 + 0.5j)  (0.129099 + 0.0j)  (0.856349 + 0.0j)]
      >>> chop(A - L*L.H)
      [0.0  0.0  0.0]
      [0.0  0.0  0.0]
      [0.0  0.0  0.0]
  
  Attempted Cholesky decomposition of a matrix that is not positive
  definite::
  
      >>> A = -eye(3) + hilbert(3)
      >>> L = cholesky(A)
      Traceback (most recent call last):
        ...
      ValueError: matrix is not positive-definite
  
  **References**
  
  1. [Wikipedia]_ http://en.wikipedia.org/wiki/Cholesky_decomposition
docstr_tok: ["Cholesky","decomposition","of","a","symmetric","positive-definite","matrix","`","A","`",".","Returns","a","lower","triangular","matrix","`","L","`","such","that","`","A","=","L","\\times","L^T","`",".","More","generally",",","for","a","complex","Hermitian","positive-definite","matrix",",","a","Cholesky","decomposition","satisfying","`","A","=","L","\\times","L^H","`","is","returned",".","The","Cholesky","decomposition","can","be","used","to","solve","linear","equation","systems","twice","as","efficiently","as","LU","decomposition",",","or","to","test","whether","`","A","`","is","positive-definite",".","The","optional","parameter","``","tol","``","determines","the","tolerance","for","verifying","positive-definiteness",".","*","*","Examples","*","*","Cholesky","decomposition","of","a","positive-definite","symmetric","matrix",":",":",">",">",">","from","mpmath","import","*",">",">",">","mp.dps","=","25",";","mp.pretty","=","True",">",">",">","A","=","eye","(","3",")","+","hilbert","(","3",")",">",">",">","nprint","(","A",")","[","2.0","0.5","0.333333","]","[","0.5","1.33333","0.25","]","[","0.333333","0.25","1.2","]",">",">",">","L","=","cholesky","(","A",")",">",">",">","nprint","(","L",")","[","1.41421","0.0","0.0","]","[","0.353553","1.09924","0.0","]","[","0.235702","0.15162","1.05899","]",">",">",">","chop","(","A","-","L","*","L.T",")","[","0.0","0.0","0.0","]","[","0.0","0.0","0.0","]","[","0.0","0.0","0.0","]","Cholesky","decomposition","of","a","Hermitian","matrix",":",":",">",">",">","A","=","eye","(","3",")","+","matrix","(","[","[","0,0.25j",",","-0.5j","]",",","[","-0.25j,0,0","]",",","[","0.5j,0,0","]","]",")",">",">",">","L","=","cholesky","(","A",")",">",">",">","nprint","(","L",")","[","1.0","0.0","0.0","]","[","(","0.0","-","0.25j",")","(","0.968246","+","0.0j",")","0.0","]","[","(","0.0","+","0.5j",")","(","0.129099","+","0.0j",")","(","0.856349","+","0.0j",")","]",">",">",">","chop","(","A","-","L","*","L.H",")","[","0.0","0.0","0.0","]","[","0.0","0.0","0.0","]","[","0.0","0.0","0.0","]","Attempted","Cholesky","decomposition","of","a","matrix","that","is","not","positive","definite",":",":",">",">",">","A","=","-eye","(","3",")","+","hilbert","(","3",")",">",">",">","L","=","cholesky","(","A",")","Traceback","(","most","recent","call","last",")",":","...","ValueError",":","matrix","is","not","positive-definite","*","*","References","*","*","1",".","[","Wikipedia","]","_","http",":","\/\/en.wikipedia.org\/wiki\/Cholesky_decomposition"]
code: def cholesky(ctx, A, tol=None):
      r"""
      Cholesky decomposition of a symmetric positive-definite matrix `A`.
      Returns a lower triangular matrix `L` such that `A = L \times L^T`.
      More generally, for a complex Hermitian positive-definite matrix,
      a Cholesky decomposition satisfying `A = L \times L^H` is returned.
  
      The Cholesky decomposition can be used to solve linear equation
      systems twice as efficiently as LU decomposition, or to
      test whether `A` is positive-definite.
  
      The optional parameter ``tol`` determines the tolerance for
      verifying positive-definiteness.
  
      **Examples**
  
      Cholesky decomposition of a positive-definite symmetric matrix::
  
          >>> from mpmath import *
          >>> mp.dps = 25; mp.pretty = True
          >>> A = eye(3) + hilbert(3)
          >>> nprint(A)
          [     2.0      0.5  0.333333]
          [     0.5  1.33333      0.25]
          [0.333333     0.25       1.2]
          >>> L = cholesky(A)
          >>> nprint(L)
          [ 1.41421      0.0      0.0]
          [0.353553  1.09924      0.0]
          [0.235702  0.15162  1.05899]
          >>> chop(A - L*L.T)
          [0.0  0.0  0.0]
          [0.0  0.0  0.0]
          [0.0  0.0  0.0]
  
      Cholesky decomposition of a Hermitian matrix::
  
          >>> A = eye(3) + matrix([[0,0.25j,-0.5j],[-0.25j,0,0],[0.5j,0,0]])
          >>> L = cholesky(A)
          >>> nprint(L)
          [          1.0                0.0                0.0]
          [(0.0 - 0.25j)  (0.968246 + 0.0j)                0.0]
          [ (0.0 + 0.5j)  (0.129099 + 0.0j)  (0.856349 + 0.0j)]
          >>> chop(A - L*L.H)
          [0.0  0.0  0.0]
          [0.0  0.0  0.0]
          [0.0  0.0  0.0]
  
      Attempted Cholesky decomposition of a matrix that is not positive
      definite::
  
          >>> A = -eye(3) + hilbert(3)
          >>> L = cholesky(A)
          Traceback (most recent call last):
            ...
          ValueError: matrix is not positive-definite
  
      **References**
  
      1. [Wikipedia]_ http://en.wikipedia.org/wiki/Cholesky_decomposition
  
      """
      if not isinstance(A, ctx.matrix):
          raise RuntimeError("A should be a type of ctx.matrix")
      if not A.rows == A.cols:
          raise ValueError("need n*n matrix")
      if tol is None:
          tol = +ctx.eps
      n = A.rows
      L = ctx.matrix(n)
      for j in xrange(n):
          c = ctx.re(A[j, j])
          if abs(c - A[j, j]) > tol:
              raise ValueError("matrix is not Hermitian")
          s = c - ctx.fsum(
              (L[j, k] for k in xrange(j)), absolute=True, squared=True
          )
          if s < tol:
              raise ValueError("matrix is not positive-definite")
          L[j, j] = ctx.sqrt(s)
          for i in xrange(j, n):
              it1 = (L[i, k] for k in xrange(j))
              it2 = (L[j, k] for k in xrange(j))
              t = ctx.fdot(it1, it2, conjugate=True)
              L[i, j] = (A[i, j] - t) / L[j, j]
      return L
  
imports: from copy import copy
  from ..libmp.backend import xrange
label_desc: Use image node_id 12 for calling the LinearAlgebraMethods obj's underlying member method code with example usage: obj.cholesky(ctx, A, tol) and returns: L