#NEWLINE# def cholesky_solve( ctx , A , b , **kwargs ) : #NEWLINE# #INDENT# '\n        Ax = b => x\n\n        Solve a symmetric positive-definite linear equation system.\n        This is twice as efficient as lu_solve.\n\n        Typical use cases:\n        * A.T*A\n        * Hessian matrix\n        * differential equations\n        ' #NEWLINE# prec = ctx . prec #NEWLINE# try : #NEWLINE# #INDENT# ctx . prec += 10 #NEWLINE# ( A , b ) = ( ctx . matrix ( A , ** kwargs ) . copy ( ) , ctx . matrix ( b , ** kwargs ) . copy ( ) ) #NEWLINE# if ( A . rows != A . cols ) : #NEWLINE# #INDENT# raise ValueError ( 'can only solve determined system' ) #NEWLINE# #UNINDENT# L = ctx . cholesky ( A ) #NEWLINE# n = L . rows #NEWLINE# if ( len ( b ) != n ) : #NEWLINE# #INDENT# raise ValueError ( 'Value should be equal to n' ) #NEWLINE# #UNINDENT# for i in xrange ( n ) : #NEWLINE# #INDENT# b [ i ] -= ctx . fsum ( ( ( L [ ( i , j ) ] * b [ j ] ) for j in xrange ( i ) ) ) #NEWLINE# b [ i ] /= L [ ( i , i ) ] #NEWLINE# #UNINDENT# x = ctx . U_solve ( L . T , b ) #NEWLINE# return i #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# ctx . prec = prec