mojolearn.solve#
- mojolearn.solve(a, b, *, numeric_mode=None)[source]#
Solve the square linear system
a @ x = b.Follows
numpy.linalg.solve, computed by LU factorization with partial pivoting (as lu_factor() and lu_solve()). A singular matrix gives aRuntimeWarningrather than an exception.- Parameters:
a (array-like of shape (n, n))
b (array-like of shape (n,) or (n, nrhs))
numeric_mode ({“identical”, “fast”} or None, default None) – Numeric mode for this call. None uses the package default (
"identical"unless changed)."identical"gives the same bits on NVIDIA and AMD GPUs;"fast"applies on Apple GPUs.
- Returns:
x (ndarray of shape (n,) or (n, nrhs), float32)
- Raises:
ValueError – If
ais not square orbhas the wrong number of rows.
Examples
>>> import numpy as np, mojolearn >>> A = np.random.default_rng(0).random((8, 8), dtype=np.float32) + 8 * np.eye(8, dtype=np.float32) >>> x = mojolearn.solve(A, np.ones(8, dtype=np.float32))