def LDL(matlist, K):
 new_matlist = copy.deepcopy(matlist)
 nrow = len(new_matlist)
 (L, D) = (eye(nrow, K), eye(nrow, K))
 for i in range(nrow):
  for j in range((i + 1)):
   a = K.zero
   for k in range(j):
    a += ((L[i][k] * L[j][k]) * D[k][k])
   if (i == j):
    D[j][j] = (new_matlist[j][j] - a)
   else:
    L[i][j] = ((new_matlist[i][j] - a) / D[j][j])
 return (L, D, conjugate_transpose(L, K))

def LDL ( matlist , K ) : new_matlist = copy . deepcopy ( matlist ) nrow = len ( new_matlist ) ( L , D ) = ( eye ( nrow , K ) , eye ( nrow , K ) ) for i in range ( nrow ) : for j in range ( ( i + 1 ) ) : a = K . zero for k in range ( j ) : a += ( ( L [ i ] [ k ] * L [ j ] [ k ] ) * D [ k ] [ k ] ) if ( i == j ) : D [ j ] [ j ] = ( new_matlist [ j ] [ j ] - a ) else : L [ i ] [ j ] = ( ( new_matlist [ i ] [ j ] - a ) / D [ j ] [ j ] ) return ( L , D , conjugate_transpose ( L , K ) )
performs the ldl decomposition of a hermitian matrix and returns l .