mojolearn.solve#

mojolearn.solve(a, b, *, numeric_mode=None)#

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 a RuntimeWarning rather 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). In identical mode, mojolearn returns the same bits on Apple, NVIDIA and AMD GPUs. "fast" is available on Apple GPUs only.

Returns:

x (ndarray of shape (n,) or (n, nrhs), float32)

Raises:

ValueError – If a is not square or b has 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))