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

Function solve

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

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

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