docstr: 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.
docstr_tok: ["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","."]
code: 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
  
imports: from copy import copy
  from ..libmp.backend import xrange
label_desc: Use image node_id 6 for calling the LinearAlgebraMethods obj's underlying member method code with example usage: obj.lu(ctx, A) and returns: P,  L,  U