MCPcopy
hub / github.com/dask/dask / lu

Function lu

dask/array/linalg.py:978–1111  ·  view source on GitHub ↗

Compute the lu decomposition of a matrix. Examples -------- >>> p, l, u = da.linalg.lu(x) # doctest: +SKIP Returns ------- p: Array, permutation matrix l: Array, lower triangular matrix with unit diagonal. u: Array, upper triangular matrix

(a)

Source from the content-addressed store, hash-verified

976
977
978def lu(a):
979 """
980 Compute the lu decomposition of a matrix.
981
982 Examples
983 --------
984
985 >>> p, l, u = da.linalg.lu(x) # doctest: +SKIP
986
987 Returns
988 -------
989
990 p: Array, permutation matrix
991 l: Array, lower triangular matrix with unit diagonal.
992 u: Array, upper triangular matrix
993 """
994 import scipy.linalg
995
996 if a.ndim != 2:
997 raise ValueError("Dimension must be 2 to perform lu decomposition")
998
999 xdim, ydim = a.shape
1000 if xdim != ydim:
1001 raise ValueError("Input must be a square matrix to perform lu decomposition")
1002 if len(set(a.chunks[0] + a.chunks[1])) != 1:
1003 msg = (
1004 "All chunks must be a square matrix to perform lu decomposition. "
1005 "Use .rechunk method to change the size of chunks."
1006 )
1007 raise ValueError(msg)
1008
1009 vdim = len(a.chunks[0])
1010 hdim = len(a.chunks[1])
1011
1012 token = tokenize(a)
1013 name_lu = f"lu-lu-{token}"
1014
1015 name_p = f"lu-p-{token}"
1016 name_l = f"lu-l-{token}"
1017 name_u = f"lu-u-{token}"
1018
1019 # for internal calculation
1020 name_p_inv = f"lu-p-inv-{token}"
1021 name_l_permuted = f"lu-l-permute-{token}"
1022 name_u_transposed = f"lu-u-transpose-{token}"
1023 name_plu_dot = f"lu-plu-dot-{token}"
1024 name_lu_dot = f"lu-lu-dot-{token}"
1025
1026 dsk = {}
1027 for i in range(min(vdim, hdim)):
1028 target = (a.name, i, i)
1029 if i > 0:
1030 prevs = []
1031 for p in range(i):
1032 prev = name_plu_dot, i, p, p, i
1033 dsk[prev] = (np.dot, (name_l_permuted, i, p), (name_u, p, i))
1034 prevs.append(prev)
1035 target = (operator.sub, target, (sum, prevs))

Callers 1

solveFunction · 0.85

Calls 7

meta_from_arrayFunction · 0.90
ArrayClass · 0.90
setClass · 0.85
minFunction · 0.85
from_collectionsMethod · 0.80
tokenizeFunction · 0.50
onesMethod · 0.45

Tested by

no test coverage detected