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

Function solve

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

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