docstr: Ax = b => x
  
  Solve a symmetric positive-definite linear equation system.
  This is twice as efficient as lu_solve.
  
  Typical use cases:
  * A.T*A
  * Hessian matrix
  * differential equations
docstr_tok: ["Ax","=","b","=",">","x","Solve","a","symmetric","positive-definite","linear","equation","system",".","This","is","twice","as","efficient","as","lu_solve",".","Typical","use","cases",":","*","A.T","*","A","*","Hessian","matrix","*","differential","equations"]
code: def cholesky_solve(ctx, A, b, **kwargs):
      """
      Ax = b => x
  
      Solve a symmetric positive-definite linear equation system.
      This is twice as efficient as lu_solve.
  
      Typical use cases:
      * A.T*A
      * Hessian matrix
      * differential equations
      """
      prec = ctx.prec
      try:
          ctx.prec += 10
          # do not overwrite A nor b
          A, b = (
              ctx.matrix(A, **kwargs).copy(),
              ctx.matrix(b, **kwargs).copy(),
          )
          if A.rows != A.cols:
              raise ValueError("can only solve determined system")
          # Cholesky factorization
          L = ctx.cholesky(A)
          # solve
          n = L.rows
          if len(b) != n:
              raise ValueError("Value should be equal to n")
          for i in xrange(n):
              b[i] -= ctx.fsum(L[i, j] * b[j] for j in xrange(i))
              b[i] /= L[i, i]
          x = ctx.U_solve(L.T, b)
          return x
      finally:
          ctx.prec = prec
  
imports: from copy import copy
  from ..libmp.backend import xrange
label_desc: Use image node_id 13 for calling the LinearAlgebraMethods obj's underlying member method code with example usage: obj.cholesky_solve(ctx, A, b) and returns: x