MCPcopy
hub / github.com/dask/dask / solve

Function solve

dask/array/linalg.py:1208–1265  ·  view source on GitHub ↗

Solve the equation ``a x = b`` for ``x``. By default, use LU decomposition and forward / backward substitutions. When ``assume_a = "pos"`` use Cholesky decomposition. Parameters ---------- a : (M, M) array_like A square matrix. b : (M,) or (M, N) array_like

(a, b, sym_pos=None, assume_a="gen")

Source from the content-addressed store, hash-verified

1206
1207
1208def solve(a, b, sym_pos=None, assume_a="gen"):
1209 """
1210 Solve the equation ``a x = b`` for ``x``. By default, use LU
1211 decomposition and forward / backward substitutions. When ``assume_a = "pos"``
1212 use Cholesky decomposition.
1213
1214 Parameters
1215 ----------
1216 a : (M, M) array_like
1217 A square matrix.
1218 b : (M,) or (M, N) array_like
1219 Right-hand side matrix in ``a x = b``.
1220 sym_pos : bool, optional
1221 Assume a is symmetric and positive definite. If ``True``, use Cholesky
1222 decomposition.
1223
1224 .. note::
1225 ``sym_pos`` is deprecated and will be removed in a future version.
1226 Use ``assume_a = 'pos'`` instead.
1227
1228 assume_a : {'gen', 'pos'}, optional
1229 Type of data matrix. It is used to choose the dedicated solver.
1230 Note that Dask does not support 'her' and 'sym' types.
1231
1232 .. versionchanged:: 2022.8.0
1233 ``assume_a = 'pos'`` was previously defined as ``sym_pos = True``.
1234
1235 Returns
1236 -------
1237 x : (M,) or (M, N) Array
1238 Solution to the system ``a x = b``. Shape of the return matches the
1239 shape of `b`.
1240
1241 See Also
1242 --------
1243 scipy.linalg.solve
1244 """
1245 if sym_pos is not None:
1246 warnings.warn(
1247 "The sym_pos keyword is deprecated and should be replaced by using ``assume_a = 'pos'``."
1248 "``sym_pos`` will be removed in a future version.",
1249 category=FutureWarning,
1250 )
1251 if sym_pos:
1252 assume_a = "pos"
1253
1254 if assume_a == "pos":
1255 l, u = _cholesky(a)
1256 elif assume_a == "gen":
1257 p, l, u = lu(a)
1258 b = p.T.dot(b)
1259 else:
1260 raise ValueError(
1261 f"{assume_a = } is not a recognized matrix structure, valid structures in Dask are 'pos' and 'gen'."
1262 )
1263
1264 uy = solve_triangular(l, b, lower=True)
1265 return solve_triangular(u, uy)

Callers 1

invFunction · 0.85

Calls 4

_choleskyFunction · 0.85
luFunction · 0.85
solve_triangularFunction · 0.85
dotMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…