(ctx, A)
return P, L, U
A -> P, L, U

        LU factorisation of a square matrix A. L is the lower, U the upper part.
        P is the permutation matrix indicating the row swaps.

        P*A = L*U

        If you need efficiency, use the low-level method LU_decomp instead, it's
        much more memory efficient.
A -> P, L, U
A - > P L U
def lu(ctx, A):
        """
        A -> P, L, U

        LU factorisation of a square matrix A. L is the lower, U the upper part.
        P is the permutation matrix indicating the row swaps.

        P*A = L*U

        If you need efficiency, use the low-level method LU_decomp instead, it's
        much more memory efficient.
        """
        # get factorization
        A, p = ctx.LU_decomp(A)
        n = A.rows
        L = ctx.matrix(n)
        U = ctx.matrix(n)
        for i in xrange(n):
            for j in xrange(n):
                if i > j:
                    L[i,j] = A[i,j]
                elif i == j:
                    L[i,j] = 1
                    U[i,j] = A[i,j]
                else:
                    U[i,j] = A[i,j]
        # calculate permutation matrix
        P = ctx.eye(n)
        for k in xrange(len(p)):
            ctx.swap_row(P, k, p[k])
        return P, L, U
def lu ( ctx , A ) : # get factorization A , p = ctx . LU_decomp ( A ) n = A . rows L = ctx . matrix ( n ) U = ctx . matrix ( n ) for i in xrange ( n ) : for j in xrange ( n ) : if i > j : L [ i , j ] = A [ i , j ] elif i == j : L [ i , j ] = 1 U [ i , j ] = A [ i , j ] else : U [ i , j ] = A [ i , j ] # calculate permutation matrix P = ctx . eye ( n ) for k in xrange ( len ( p ) ) : ctx . swap_row ( P , k , p [ k ] ) return P , L , U