MCPcopy Create free account
hub / github.com/dask/dask / lu

Function lu

dask/array/linalg.py:973–1106  ·  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

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